mirror of
https://github.com/oatpp/oatpp.git
synced 2024-11-21 03:14:51 +08:00
Merge pull request #667 from doufu3344/dis-escape-utf8char
Support for disabling escaping of non-ASCII when serializing DTOs
This commit is contained in:
commit
6063b57b25
@ -77,7 +77,9 @@ v_buff_size Utils::calcEscapedStringSize(const char* data, v_buff_size size, v_b
|
||||
safeSize = i;
|
||||
}
|
||||
i += charSize;
|
||||
if(charSize < 4) {
|
||||
if (!(flags & FLAG_ESCAPE_UTF8CHAR)) {
|
||||
result += charSize; // output as-is
|
||||
} else if(charSize < 4) {
|
||||
result += 6; // '\uFFFF' - 6 chars
|
||||
} else if(charSize == 4) {
|
||||
result += 12; // '\uFFFF\uFFFF' - 12 chars surrogate pair
|
||||
@ -282,7 +284,13 @@ oatpp::String Utils::escapeString(const char* data, v_buff_size size, v_uint32 f
|
||||
else {
|
||||
v_buff_size charSize = oatpp::encoding::Unicode::getUtf8CharSequenceLength(a);
|
||||
if (charSize != 0) {
|
||||
pos += escapeUtf8Char(&data[i], &resultData[pos]);
|
||||
if (!(flags & FLAG_ESCAPE_UTF8CHAR)) {
|
||||
std::memcpy((void*)&resultData[pos], (void*)&data[i], charSize);
|
||||
pos += charSize;
|
||||
}
|
||||
else {
|
||||
pos += escapeUtf8Char(&data[i], &resultData[pos]);
|
||||
}
|
||||
i += charSize;
|
||||
}
|
||||
else {
|
||||
|
@ -40,8 +40,9 @@ class Utils {
|
||||
public:
|
||||
|
||||
static constexpr v_uint32 FLAG_ESCAPE_SOLIDUS = 1;
|
||||
static constexpr v_uint32 FLAG_ESCAPE_UTF8CHAR = 2;
|
||||
|
||||
static constexpr v_uint32 FLAG_ESCAPE_ALL = FLAG_ESCAPE_SOLIDUS;
|
||||
static constexpr v_uint32 FLAG_ESCAPE_ALL = FLAG_ESCAPE_SOLIDUS | FLAG_ESCAPE_UTF8CHAR;
|
||||
|
||||
public:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user