mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-03 15:58:23 +02:00
Merge pull request #315 from fbraem/develop
Solve wrong escaping of unicode characters
This commit is contained in:
commit
1cd745996c
@ -92,41 +92,41 @@ void Stringifier::formatString(const std::string& value, std::ostream& out)
|
|||||||
out << '"';
|
out << '"';
|
||||||
for (std::string::const_iterator it = value.begin(); it != value.end(); ++it)
|
for (std::string::const_iterator it = value.begin(); it != value.end(); ++it)
|
||||||
{
|
{
|
||||||
switch (*it)
|
if (*it == 0x20 ||
|
||||||
{
|
*it == 0x21 ||
|
||||||
case '"':
|
(*it >= 0x23 && *it <= 0x2E) ||
|
||||||
|
(*it >= 0x30 && *it <= 0x5B) ||
|
||||||
|
(*it >= 0x5D && *it <= 0xFF))
|
||||||
|
out << *it;
|
||||||
|
else if (*it == '"')
|
||||||
out << "\\\"";
|
out << "\\\"";
|
||||||
break;
|
else if (*it == '\\')
|
||||||
case '\\':
|
|
||||||
out << "\\\\";
|
out << "\\\\";
|
||||||
break;
|
else if (*it == '\b')
|
||||||
case '\b':
|
|
||||||
out << "\\b";
|
out << "\\b";
|
||||||
break;
|
else if (*it == '\f')
|
||||||
case '\f':
|
|
||||||
out << "\\f";
|
out << "\\f";
|
||||||
break;
|
else if (*it == '\n')
|
||||||
case '\n':
|
|
||||||
out << "\\n";
|
out << "\\n";
|
||||||
break;
|
else if (*it == '\r')
|
||||||
case '\r':
|
|
||||||
out << "\\r";
|
out << "\\r";
|
||||||
break;
|
else if (*it == '\t')
|
||||||
case '\t':
|
|
||||||
out << "\\t";
|
out << "\\t";
|
||||||
break;
|
else if ( *it == '\0' )
|
||||||
default:
|
out << "\\u0000";
|
||||||
{
|
|
||||||
if ( *it > 0 && *it <= 0x1F )
|
|
||||||
{
|
|
||||||
out << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*it);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out << *it;
|
const char *hexdigits = "0123456789ABCDEF";
|
||||||
}
|
unsigned long u = (std::min)(static_cast<unsigned long>(static_cast<unsigned char>(*it)), 0xFFFFul);
|
||||||
break;
|
int d1 = u / 4096; u -= d1 * 4096;
|
||||||
}
|
int d2 = u / 256; u -= d2 * 256;
|
||||||
|
int d3 = u / 16; u -= d3 * 16;
|
||||||
|
int d4 = u;
|
||||||
|
out << "\\u";
|
||||||
|
out << hexdigits[d1];
|
||||||
|
out << hexdigits[d2];
|
||||||
|
out << hexdigits[d3];
|
||||||
|
out << hexdigits[d4];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << '"';
|
out << '"';
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
void write(BinaryWriter& writer);
|
void write(BinaryWriter& writer);
|
||||||
/// Writes the header
|
/// Writes the header
|
||||||
|
|
||||||
std::size_t getMessageLength() const;
|
Int32 getMessageLength() const;
|
||||||
/// Returns the message length
|
/// Returns the message length
|
||||||
|
|
||||||
OpCode opCode() const;
|
OpCode opCode() const;
|
||||||
@ -95,10 +95,10 @@ private:
|
|||||||
MessageHeader(OpCode opcode);
|
MessageHeader(OpCode opcode);
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
|
|
||||||
void setMessageLength(std::size_t length);
|
void setMessageLength(Int32 length);
|
||||||
/// Sets the message length
|
/// Sets the message length
|
||||||
|
|
||||||
std::size_t _messageLength;
|
Int32 _messageLength;
|
||||||
Int32 _requestID;
|
Int32 _requestID;
|
||||||
Int32 _responseTo;
|
Int32 _responseTo;
|
||||||
OpCode _opCode;
|
OpCode _opCode;
|
||||||
@ -113,13 +113,13 @@ inline MessageHeader::OpCode MessageHeader::opCode() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t MessageHeader::getMessageLength() const
|
inline Int32 MessageHeader::getMessageLength() const
|
||||||
{
|
{
|
||||||
return _messageLength;
|
return _messageLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void MessageHeader::setMessageLength(std::size_t length)
|
inline void MessageHeader::setMessageLength(Int32 length)
|
||||||
{
|
{
|
||||||
_messageLength = MSG_HEADER_SIZE + length;
|
_messageLength = MSG_HEADER_SIZE + length;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user