Fix escaping/unescaping in wxLongStringProperty

wxPropertyGrid::ExpandEscapeSequences() function should convert all valid
escape sequences (\r, \n, \t, \\) to the corresponding single characters
(CR, LF, TAB, backslash, accordingly) and
wxPropertyGrid::CreateEscapeSequences() function should do the reverse
operation and convert these raw characters to the corresponding escape
sequences.

Closes #17896.
This commit is contained in:
mikek
2017-07-06 23:04:37 +02:00
committed by Artur Wieczorek
parent 5292f77ab4
commit 2d8657d37c
3 changed files with 26 additions and 39 deletions

View File

@@ -145,6 +145,7 @@ All (GUI):
- Add support for bitmaps to wxToggleButton XRC handler (tm). - Add support for bitmaps to wxToggleButton XRC handler (tm).
- Fix wxGCDC::SetDeviceClippingRegion(). - Fix wxGCDC::SetDeviceClippingRegion().
- Never restore size smaller than the best one in wxPersistentTLW. - Never restore size smaller than the best one in wxPersistentTLW.
- Fix escaping/unescaping characters in wxLongStringProperty in wxPG (mikek).
wxGTK: wxGTK:

View File

@@ -543,8 +543,14 @@ wxPG_PROP_CLASS_SPECIFIC_3 = 0x00400000
@subsection wxLongStringProperty @subsection wxLongStringProperty
Like wxStringProperty, but has a button that triggers a small text editor Like wxStringProperty, but has a button that triggers a small text editor
dialog. Note that in long string values, tabs are represented by "\t" and dialog. Note that in long string values, some control characters are
line break by "\n". escaped: tab is represented by "\t", line break by "\n", carriage return
by "\r" and backslash character by "\\". If another character is preceded
by backslash, the backslash is skipped.
Note also that depending on the system (port), some sequences of special
characters, like e.g. "\r\n", can be interpreted and presented in
a different way in the editor and therefore such sequences may not be
the same before and after the edition.
To display custom dialog on button press, you can subclass To display custom dialog on button press, you can subclass
wxLongStringProperty and implement OnButtonClick, like this: wxLongStringProperty and implement OnButtonClick, like this:

View File

@@ -1744,9 +1744,8 @@ wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, const wxStri
bool prev_is_slash = false; bool prev_is_slash = false;
wxString::const_iterator i = src_str.begin(); wxString::const_iterator i;
for ( i = src_str.begin(); i != src_str.end(); ++i )
for ( ; i != src_str.end(); ++i )
{ {
wxUniChar a = *i; wxUniChar a = *i;
@@ -1759,13 +1758,9 @@ wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, const wxStri
else else
{ {
if ( a == wxS('n') ) if ( a == wxS('n') )
{
#ifdef __WXMSW__
dst_str << wxS('\n'); dst_str << wxS('\n');
#else else if ( a == wxS('r') )
dst_str << wxS('\n'); dst_str << wxS('\r');
#endif
}
else if ( a == wxS('t') ) else if ( a == wxS('t') )
dst_str << wxS('\t'); dst_str << wxS('\t');
else else
@@ -1801,39 +1796,24 @@ wxString& wxPropertyGrid::CreateEscapeSequences( wxString& dst_str, const wxStri
} }
wxString::const_iterator i; wxString::const_iterator i;
wxUniChar prev_a = wxS('\0');
for ( i = src_str.begin(); i != src_str.end(); ++i ) for ( i = src_str.begin(); i != src_str.end(); ++i )
{ {
wxUniChar a = *i; wxUniChar a = *i;
if ( a >= wxS(' ') ) if ( a == wxS('\r') )
{ // Carriage Return.
// This surely is not something that requires an escape sequence. dst_str << wxS("\\r");
dst_str << a; else if ( a == wxS('\n') )
} // Line Feed.
dst_str << wxS("\\n");
else if ( a == wxS('\t') )
// Tab.
dst_str << wxS("\\t");
else if ( a == wxS('\\') )
// Escape character (backslash).
dst_str << wxS("\\\\");
else else
{ dst_str << a;
// This might need...
if ( a == wxS('\r') )
{
// DOS style line end.
// Already taken care below
}
else if ( a == wxS('\n') )
// UNIX style line end.
dst_str << wxS("\\n");
else if ( a == wxS('\t') )
// Tab.
dst_str << wxS('\t');
else
{
//wxLogDebug(wxS("WARNING: Could not create escape sequence for character #%i"),(int)a);
dst_str << a;
}
}
prev_a = a;
} }
return dst_str; return dst_str;
} }