Skip to content

Commit d736dad

Browse files
committed
Fix Formatter UTF8 encoding
1 parent 22e244c commit d736dad

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Sming/Core/Data/Format/Formatter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ unsigned escapeControls(String& value, Options options)
6464
} else if(uint8_t(c) < 0x20) {
6565
extra += 3; // "\xnn"
6666
} else if((c & 0x80) && options[Option::utf8]) {
67-
// Characters such as £ (0xa3) are escaped to 0xc2 0xa3 in UTF-8
68-
extra += 1; // 0xc2
67+
// Characters from U+0080 to U+07FF are encoded in two bytes in UTF-8
68+
extra += 1;
6969
}
7070
}
7171
if(extra == 0) {
@@ -100,7 +100,8 @@ unsigned escapeControls(String& value, Options options)
100100
*out++ = hexchar(uint8_t(c) >> 4);
101101
c = hexchar(uint8_t(c) & 0x0f);
102102
} else if((c & 0x80) && options[Option::utf8]) {
103-
*out++ = 0xc2;
103+
*out++ = 0xc0 | (c >> 6);
104+
c = 0x80 | (c & 0x3f);
104105
}
105106
*out++ = c;
106107
}

0 commit comments

Comments
 (0)