mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-23 23:16:39 +01:00
Merge pull request #2867 from vfjpl/poco-1.10.0
unescape Backslash char in UTF8 unescape method
This commit is contained in:
commit
5f0e0a0374
@ -50,3 +50,4 @@ Jeff Adams
|
||||
Martin Osborne
|
||||
Björn Schramke
|
||||
Francis Andre
|
||||
Kacper Piwiński
|
||||
|
@ -264,42 +264,74 @@ std::string UTF8::unescape(const std::string::const_iterator& begin, const std::
|
||||
//Invalid sequence!
|
||||
}
|
||||
|
||||
if (*it == 'n')
|
||||
switch (*it)
|
||||
{
|
||||
case 'U':
|
||||
{
|
||||
char digs[9];
|
||||
std::memset(digs, 0, 9);
|
||||
unsigned int dno = 0;
|
||||
|
||||
it++;
|
||||
while (it != end && Ascii::isHexDigit(*it) && dno < 8)
|
||||
{
|
||||
digs[dno++] = *it++;
|
||||
}
|
||||
if (dno > 0)
|
||||
{
|
||||
ch = std::strtol(digs, NULL, 16);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '\\':
|
||||
{
|
||||
ch = '\\';
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
case 'n':
|
||||
{
|
||||
ch = '\n';
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
else if (*it == 't')
|
||||
case 't':
|
||||
{
|
||||
ch = '\t';
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
else if (*it == 'r')
|
||||
case 'r':
|
||||
{
|
||||
ch = '\r';
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
else if (*it == 'b')
|
||||
case 'b':
|
||||
{
|
||||
ch = '\b';
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
else if (*it == 'f')
|
||||
case 'f':
|
||||
{
|
||||
ch = '\f';
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
else if (*it == 'v')
|
||||
case 'v':
|
||||
{
|
||||
ch = '\v';
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
else if (*it == 'a')
|
||||
case 'a':
|
||||
{
|
||||
ch = '\a';
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
else if (*it == 'u')
|
||||
case 'u':
|
||||
{
|
||||
char digs[5];
|
||||
std::memset(digs, 0, 5);
|
||||
@ -345,23 +377,14 @@ std::string UTF8::unescape(const std::string::const_iterator& begin, const std::
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (*it == 'U')
|
||||
default:
|
||||
{
|
||||
char digs[9];
|
||||
std::memset(digs, 0, 9);
|
||||
unsigned int dno = 0;
|
||||
|
||||
it++;
|
||||
while (it != end && Ascii::isHexDigit(*it) && dno < 8)
|
||||
{
|
||||
digs[dno++] = *it++;
|
||||
}
|
||||
if (dno > 0)
|
||||
{
|
||||
ch = std::strtol(digs, NULL, 16);
|
||||
}
|
||||
//Invalid sequence!
|
||||
break;
|
||||
}
|
||||
}//end switch
|
||||
}
|
||||
|
||||
unsigned char utf8[4];
|
||||
|
@ -96,9 +96,11 @@ void UTF8StringTest::testUnescape()
|
||||
{
|
||||
std::string s1("A \\t, a \\u000B, and an \\u0007 walk into a |, and the barman says \\u0402");
|
||||
std::string s2("A \\t, a \\v, and an \\a walk into a |, and the barman says \\u0402");
|
||||
std::string s3("\\\\");
|
||||
|
||||
assertTrue (UTF8::unescape(s1) == "A \t, a \v, and an \a walk into a |, and the barman says \xD0\x82");
|
||||
assertTrue (UTF8::unescape(s2) == "A \t, a \v, and an \a walk into a |, and the barman says \xD0\x82");
|
||||
assertTrue (UTF8::unescape(s3) == "\\");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user