From 36785a4ad7ec9b219fad48490448df22bf76c7ec Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Fri, 23 Jun 2023 15:33:12 -0700 Subject: [PATCH] Make trimming of space characters optional It turns out that leading spaces are nice when editing trace name suffixes, so UIforETW needs to support them. --- UIforETW/UIforETWDlg.cpp | 3 ++- UIforETW/Utility.cpp | 14 +++++++++----- UIforETW/Utility.h | 5 +++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/UIforETW/UIforETWDlg.cpp b/UIforETW/UIforETWDlg.cpp index 4ac8c478..b7f5c2d3 100644 --- a/UIforETW/UIforETWDlg.cpp +++ b/UIforETW/UIforETWDlg.cpp @@ -2503,7 +2503,8 @@ void CUIforETWDlg::FinishTraceRename() // Make sure this doesn't get double-called. if (!btTraceNameEdit_.IsWindowVisible()) return; - std::wstring newText = GetTrimmedEditControlText(btTraceNameEdit_); + // Don't trim space characters - they may be wanted. + std::wstring newText = GetTrimmedEditControlText(btTraceNameEdit_, false); std::wstring newTraceName = newText; if (validRenameDate_) newTraceName = preRenameTraceName_.substr(0, kPrefixLength) + newText; diff --git a/UIforETW/Utility.cpp b/UIforETW/Utility.cpp index 0be9e944..0133f602 100644 --- a/UIforETW/Utility.cpp +++ b/UIforETW/Utility.cpp @@ -407,13 +407,17 @@ std::wstring GetEditControlText(const HWND hEdit) return &buffer[0]; } -std::wstring GetTrimmedEditControlText(const HWND hEdit) +std::wstring GetTrimmedEditControlText(const HWND hEdit, bool trim_space) { std::wstring text = GetEditControlText(hEdit); - // Trim leading and trailing spaces. Otherwise a trailing-but-invisible \n can - // wreak havoc. This can happen when pasting from the clipboard, even on a - // single-line edit control. This issue was hitting when pasting from Signal. - const std::wstring whitespace = L" \n\r\t\f\v"; + // Trim leading and trailing problematic white-space. Otherwise a + // trailing-but-invisible \n can wreak havoc. This can happen when pasting + // from the clipboard, even on a single-line edit control. This issue was + // hitting when pasting from Signal. The space character itself is only + // trimmed optionally because it may be wanted, especially for trace names. + std::wstring whitespace = L"\n\r\t\f\v"; + if (trim_space) + whitespace += ' '; const size_t start = text.find_first_not_of(whitespace); if (start == std::wstring::npos) return L""; diff --git a/UIforETW/Utility.h b/UIforETW/Utility.h index 22345eb0..890eae02 100644 --- a/UIforETW/Utility.h +++ b/UIforETW/Utility.h @@ -40,8 +40,9 @@ void CreateRegistryKey(HKEY root, const std::wstring& subkey, const std::wstring std::wstring ReadRegistryString(HKEY root, const std::wstring& subkey, const std::wstring& valueName, bool force32Bit); std::wstring GetEditControlText(HWND hwnd); -// The Trimmed version trims leading and trailing whitespace. -std::wstring GetTrimmedEditControlText(const HWND hEdit); +// The Trimmed version trims leading and trailing whitespace characters, with +// trimming of the actual ' ' character being optional. +std::wstring GetTrimmedEditControlText(const HWND hEdit, bool trim_space=true); std::wstring AnsiToUnicode(const std::string& text); // Return a string from a format string and some printf-style arguments.