Fixed bug introduced by utf-8 patch with fix provided by Henry Ludemann. All unit tests are now passing.

This commit is contained in:
Baptiste Lepilleur 2009-11-18 17:01:09 +00:00
parent b0ab79bc5b
commit eda47b61b5

View File

@ -120,44 +120,52 @@ std::string valueToQuotedString( const char *value )
std::string result; std::string result;
result.reserve(maxsize); // to avoid lots of mallocs result.reserve(maxsize); // to avoid lots of mallocs
result += "\""; result += "\"";
for (const char* c=value; *c != 0; ++c){ for (const char* c=value; *c != 0; ++c)
switch(*c){ {
switch(*c)
{
case '\"': case '\"':
result += "\\\""; result += "\\\"";
break; break;
case '\\': case '\\':
result += "\\\\"; result += "\\\\";
break; break;
case '\b': case '\b':
result += "\\b"; result += "\\b";
break; break;
case '\f': case '\f':
result += "\\f"; result += "\\f";
break; break;
case '\n': case '\n':
result += "\\n"; result += "\\n";
break; break;
case '\r': case '\r':
result += "\\r"; result += "\\r";
break; break;
case '\t': case '\t':
result += "\\t"; result += "\\t";
break; break;
case '/': //case '/':
// Even though \/ is considered a legal escape in JSON, a bare // Even though \/ is considered a legal escape in JSON, a bare
// slash is also legal, so I see no reason to escape it. // slash is also legal, so I see no reason to escape it.
// (I hope I am not misunderstanding something.) // (I hope I am not misunderstanding something.
default: // blep notes: actually escaping \/ may be useful in javascript to avoid </
if ( isControlCharacter( *c ) ) // sequence.
{ // Should add a flag to allow this compatibility mode and prevent this
std::ostringstream oss; // sequence from occurring.
oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*c); default:
result += oss.str(); if ( isControlCharacter( *c ) )
} {
else std::ostringstream oss;
result += *c; oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*c);
result += oss.str();
}
else
{
result += *c;
}
break;
} }
break;
} }
result += "\""; result += "\"";
return result; return result;