mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 12:01:50 +00:00
fix unicode string literal escape
This commit is contained in:
parent
8b38d57966
commit
28c821006a
5 changed files with 63 additions and 6 deletions
|
|
@ -32,7 +32,7 @@ protected:
|
|||
void goBack(size_t count = 1);
|
||||
void reset();
|
||||
|
||||
int64_t parseSimpleInt(int base);
|
||||
int64_t parseSimpleInt(int base, size_t maxLength = 0xFFFFFFFF);
|
||||
dv::value parseNumber(int sign);
|
||||
dv::value parseNumber();
|
||||
StringT parseString(CharT chr, bool closeRequired = true);
|
||||
|
|
|
|||
|
|
@ -349,7 +349,10 @@ std::basic_string<CharT> BasicParser<CharT>::parseXmlName() {
|
|||
}
|
||||
|
||||
template <typename CharT>
|
||||
int64_t BasicParser<CharT>::parseSimpleInt(int base) {
|
||||
int64_t BasicParser<CharT>::parseSimpleInt(int base, size_t maxLength) {
|
||||
if (maxLength == 0) return 0;
|
||||
|
||||
size_t start = pos;
|
||||
CharT c = peek();
|
||||
int index = hexchar2int(c);
|
||||
if (index == -1 || index >= base) {
|
||||
|
|
@ -357,7 +360,7 @@ int64_t BasicParser<CharT>::parseSimpleInt(int base) {
|
|||
}
|
||||
int64_t value = index;
|
||||
pos++;
|
||||
while (hasNext()) {
|
||||
while (hasNext() && pos - start < maxLength) {
|
||||
c = source[pos];
|
||||
while (c == '_') {
|
||||
c = source[++pos];
|
||||
|
|
@ -476,7 +479,7 @@ std::basic_string<CharT> BasicParser<CharT>::parseString(
|
|||
continue;
|
||||
}
|
||||
if (c == 'u' || c == 'x') {
|
||||
int codepoint = parseSimpleInt(16);
|
||||
int codepoint = parseSimpleInt(16, c == 'u' ? 4 : 2);
|
||||
ubyte bytes[4];
|
||||
int size = util::encode_utf8(codepoint, bytes);
|
||||
CharT chars[4];
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace markdown {
|
|||
Result<wchar_t> process(std::wstring_view source, bool eraseMarkdown);
|
||||
|
||||
template <typename CharT>
|
||||
inline std::basic_string<CharT> escape(std::string_view source) {
|
||||
inline std::basic_string<CharT> escape(std::basic_string_view<CharT> source) {
|
||||
std::basic_stringstream<CharT> ss;
|
||||
int pos = 0;
|
||||
while (pos < source.size()) {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ std::string util::escape(std::string_view s, bool escapeUnicode) {
|
|||
uint cpsize;
|
||||
int codepoint = decode_utf8(cpsize, s.data() + pos);
|
||||
if (escapeUnicode) {
|
||||
ss << "\\u" << std::hex << codepoint;
|
||||
ss << "\\u" << std::setw(4) << std::setfill('0') << std::hex << codepoint;
|
||||
} else {
|
||||
ss << std::string(s.data() + pos, cpsize);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue