fixed: in Space serializer: we have to escape more characters
fixed: in SpaceParser::ReadTokenSingle the delimiter can be only if the character was not escaped git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@409 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
e195145394
commit
11ddf0f6d9
|
@ -313,12 +313,8 @@ public:
|
|||
template<class Stream>
|
||||
void SerializeTableMulti(Stream & out, bool use_indents, int level) const;
|
||||
|
||||
template<class Stream>
|
||||
static void PrintValue(Stream & out, const std::wstring & str, bool use_quote = true);
|
||||
|
||||
// for other uses
|
||||
template<class Stream>
|
||||
static void PrintValue(Stream & out, const std::string & str, bool use_quote = true);
|
||||
template<class Stream, class StringType>
|
||||
static void PrintValue(Stream & out, const StringType & str, bool use_quote = true);
|
||||
|
||||
template<class Stream>
|
||||
static void PrintKey(Stream & out, const std::wstring & str);
|
||||
|
@ -361,61 +357,28 @@ void Space::PrintLevel(Stream & out, bool use_indents, int level)
|
|||
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Space::PrintValue(Stream & out, const std::wstring & str, bool use_quote)
|
||||
|
||||
template<class Stream, class StringType>
|
||||
void Space::PrintValue(Stream & out, const StringType & str, bool use_quote)
|
||||
{
|
||||
if( use_quote )
|
||||
out << '\"';
|
||||
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
{
|
||||
if( str[i] == '\\' )
|
||||
out << L"\\\\";
|
||||
else
|
||||
if( str[i] == '"' )
|
||||
out << L"\\\"";
|
||||
else
|
||||
if( str[i] == '\r' )
|
||||
out << L"\\r";
|
||||
else
|
||||
if( str[i] == '\n' )
|
||||
out << L"\\n";
|
||||
else
|
||||
if( str[i] == 0 )
|
||||
out << L"\\0";
|
||||
else
|
||||
out << str[i];
|
||||
}
|
||||
|
||||
if( use_quote )
|
||||
out << '\"';
|
||||
}
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Space::PrintValue(Stream & out, const std::string & str, bool use_quote)
|
||||
{
|
||||
if( use_quote )
|
||||
out << '\"';
|
||||
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
{
|
||||
if( str[i] == '\\' )
|
||||
out << "\\\\";
|
||||
else
|
||||
if( str[i] == '"' )
|
||||
out << "\\\"";
|
||||
else
|
||||
if( str[i] == '\r' )
|
||||
out << "\\r";
|
||||
else
|
||||
if( str[i] == '\n' )
|
||||
out << "\\n";
|
||||
else
|
||||
if( str[i] == 0 )
|
||||
out << "\\0";
|
||||
else
|
||||
switch(str[i])
|
||||
{
|
||||
case 0: out << '\\'; out << '0'; break;
|
||||
case '\r': out << '\\'; out << 'r'; break;
|
||||
case '\n': out << '\\'; out << 'n'; break;
|
||||
case '\\': out << '\\'; out << '\\'; break;
|
||||
case '"': out << '\\'; out << '\"'; break;
|
||||
case '(': out << '\\'; out << '('; break;
|
||||
case ')': out << '\\'; out << ')'; break;
|
||||
case '=': out << '\\'; out << '='; break;
|
||||
default:
|
||||
out << str[i];
|
||||
}
|
||||
}
|
||||
|
||||
if( use_quote )
|
||||
|
|
|
@ -410,11 +410,15 @@ void SpaceParser::ReadTokenSingle(bool white_delimit, bool new_line_delimit, int
|
|||
SkipLine();
|
||||
|
||||
if( lastc == -1 ||
|
||||
lastc == list_end ||
|
||||
(delimit1 != -1 && lastc == delimit1) ||
|
||||
(delimit2 != -1 && lastc == delimit2) ||
|
||||
(white_delimit && IsWhite(lastc)) ||
|
||||
(new_line_delimit && lastc == '\n') )
|
||||
(!char_was_escaped &&
|
||||
(
|
||||
lastc == list_end ||
|
||||
(new_line_delimit && lastc == '\n') ||
|
||||
(delimit1 != -1 && lastc == delimit1) ||
|
||||
(delimit2 != -1 && lastc == delimit2)
|
||||
) ) )
|
||||
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -662,11 +666,10 @@ int SpaceParser::ReadChar()
|
|||
switch(lastc)
|
||||
{
|
||||
case '0': lastc = 0; break;
|
||||
case 'n': lastc = '\n'; break;
|
||||
case '\\': lastc = '\\'; break;
|
||||
case 'r': lastc = '\r'; break;
|
||||
case 't': lastc = '\t'; break;
|
||||
case '"': lastc = '"'; break;
|
||||
case 'r': lastc = '\r'; break;
|
||||
case 'n': lastc = '\n'; break;
|
||||
// in other cases we return the last character
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue