Skip to content

Commit 36785a4

Browse files
committedJun 23, 2023
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.
1 parent 955c771 commit 36785a4

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed
 

‎UIforETW/UIforETWDlg.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,8 @@ void CUIforETWDlg::FinishTraceRename()
25032503
// Make sure this doesn't get double-called.
25042504
if (!btTraceNameEdit_.IsWindowVisible())
25052505
return;
2506-
std::wstring newText = GetTrimmedEditControlText(btTraceNameEdit_);
2506+
// Don't trim space characters - they may be wanted.
2507+
std::wstring newText = GetTrimmedEditControlText(btTraceNameEdit_, false);
25072508
std::wstring newTraceName = newText;
25082509
if (validRenameDate_)
25092510
newTraceName = preRenameTraceName_.substr(0, kPrefixLength) + newText;

‎UIforETW/Utility.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,17 @@ std::wstring GetEditControlText(const HWND hEdit)
407407
return &buffer[0];
408408
}
409409

410-
std::wstring GetTrimmedEditControlText(const HWND hEdit)
410+
std::wstring GetTrimmedEditControlText(const HWND hEdit, bool trim_space)
411411
{
412412
std::wstring text = GetEditControlText(hEdit);
413-
// Trim leading and trailing spaces. Otherwise a trailing-but-invisible \n can
414-
// wreak havoc. This can happen when pasting from the clipboard, even on a
415-
// single-line edit control. This issue was hitting when pasting from Signal.
416-
const std::wstring whitespace = L" \n\r\t\f\v";
413+
// Trim leading and trailing problematic white-space. Otherwise a
414+
// trailing-but-invisible \n can wreak havoc. This can happen when pasting
415+
// from the clipboard, even on a single-line edit control. This issue was
416+
// hitting when pasting from Signal. The space character itself is only
417+
// trimmed optionally because it may be wanted, especially for trace names.
418+
std::wstring whitespace = L"\n\r\t\f\v";
419+
if (trim_space)
420+
whitespace += ' ';
417421
const size_t start = text.find_first_not_of(whitespace);
418422
if (start == std::wstring::npos)
419423
return L"";

‎UIforETW/Utility.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ void CreateRegistryKey(HKEY root, const std::wstring& subkey, const std::wstring
4040
std::wstring ReadRegistryString(HKEY root, const std::wstring& subkey, const std::wstring& valueName, bool force32Bit);
4141

4242
std::wstring GetEditControlText(HWND hwnd);
43-
// The Trimmed version trims leading and trailing whitespace.
44-
std::wstring GetTrimmedEditControlText(const HWND hEdit);
43+
// The Trimmed version trims leading and trailing whitespace characters, with
44+
// trimming of the actual ' ' character being optional.
45+
std::wstring GetTrimmedEditControlText(const HWND hEdit, bool trim_space=true);
4546
std::wstring AnsiToUnicode(const std::string& text);
4647

4748
// Return a string from a format string and some printf-style arguments.

0 commit comments

Comments
 (0)
Please sign in to comment.