mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add util::escape 'escapeUnicode' option
This commit is contained in:
parent
637dfa66c2
commit
6e90568d2a
3 changed files with 9 additions and 5 deletions
|
|
@ -7,7 +7,7 @@
|
|||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
std::string util::escape(std::string_view s) {
|
||||
std::string util::escape(std::string_view s, bool escapeUnicode) {
|
||||
std::stringstream ss;
|
||||
ss << '"';
|
||||
size_t pos = 0;
|
||||
|
|
@ -39,8 +39,12 @@ std::string util::escape(std::string_view s) {
|
|||
if (c & 0x80) {
|
||||
uint cpsize;
|
||||
int codepoint = decode_utf8(cpsize, s.data() + pos);
|
||||
if (escapeUnicode) {
|
||||
ss << "\\u" << std::hex << codepoint;
|
||||
} else {
|
||||
ss << std::string(s.data() + pos, cpsize);
|
||||
}
|
||||
pos += cpsize-1;
|
||||
ss << "\\u" << std::hex << codepoint;
|
||||
break;
|
||||
}
|
||||
if (c < ' ') {
|
||||
|
|
@ -57,7 +61,7 @@ std::string util::escape(std::string_view s) {
|
|||
}
|
||||
|
||||
std::string util::quote(const std::string& s) {
|
||||
return escape(s);
|
||||
return escape(s, false);
|
||||
}
|
||||
|
||||
std::wstring util::lfill(std::wstring s, uint length, wchar_t c) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue