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

@@ -1744,9 +1744,8 @@ wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, const wxStri
bool prev_is_slash = false;
wxString::const_iterator i = src_str.begin();
for ( ; i != src_str.end(); ++i )
wxString::const_iterator i;
for ( i = src_str.begin(); i != src_str.end(); ++i )
{
wxUniChar a = *i;
@@ -1759,13 +1758,9 @@ wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, const wxStri
else
{
if ( a == wxS('n') )
{
#ifdef __WXMSW__
dst_str << wxS('\n');
#else
dst_str << wxS('\n');
#endif
}
else if ( a == wxS('r') )
dst_str << wxS('\r');
else if ( a == wxS('t') )
dst_str << wxS('\t');
else
@@ -1801,39 +1796,24 @@ wxString& wxPropertyGrid::CreateEscapeSequences( wxString& dst_str, const wxStri
}
wxString::const_iterator i;
wxUniChar prev_a = wxS('\0');
for ( i = src_str.begin(); i != src_str.end(); ++i )
{
wxUniChar a = *i;
if ( a >= wxS(' ') )
{
// This surely is not something that requires an escape sequence.
dst_str << a;
}
if ( a == wxS('\r') )
// Carriage Return.
dst_str << wxS("\\r");
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
{
// 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;
dst_str << a;
}
return dst_str;
}