Skip to content

Commit

Permalink
Make trimming of space characters optional
Browse files Browse the repository at this point in the history
It turns out that leading spaces are nice when editing trace name
suffixes, so UIforETW needs to support them.
  • Loading branch information
randomascii committed Jun 23, 2023
1 parent 955c771 commit 36785a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion UIforETW/UIforETWDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions UIforETW/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"";
Expand Down
5 changes: 3 additions & 2 deletions UIforETW/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 36785a4

Please sign in to comment.