diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-03-28 17:17:11 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-07 16:41:37 +0000 |
commit | 3cd4ff83a253e098e6524df5be3a686727e4f50b (patch) | |
tree | cfbfaac4753d6321339f8653c3cabaca440afec8 /lib/jsonParse.impl.cpp | |
parent | Compile stb wrapper in C++ mode (diff) | |
download | ilt-3cd4ff83a253e098e6524df5be3a686727e4f50b.tar.bz2 ilt-3cd4ff83a253e098e6524df5be3a686727e4f50b.tar.xz ilt-3cd4ff83a253e098e6524df5be3a686727e4f50b.zip |
Initial commit of basis persistence
JSON parser lifted almost verbatim for libjsonpp running into some
custom code for populating ilt objects. Pretty minimal per object code
requirements.
Diffstat (limited to 'lib/jsonParse.impl.cpp')
-rw-r--r-- | lib/jsonParse.impl.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/jsonParse.impl.cpp b/lib/jsonParse.impl.cpp new file mode 100644 index 0000000..27e73b4 --- /dev/null +++ b/lib/jsonParse.impl.cpp @@ -0,0 +1,39 @@ +#include "jsonParse.h" + +void +json::jsonParser::LexerError(const char * msg) +{ + throw std::runtime_error(msg); +} + +void +json::jsonParser::appendEscape(const char * cphs, std::string & str) +{ + appendEscape(std::strtoul(cphs, nullptr, 16), str); +} + +void +json::jsonParser::appendEscape(unsigned long cp, std::string & str) +{ + if (cp <= 0x7F) { + str += cp; + } + else if (cp <= 0x7FF) { + str += (cp >> 6) + 192; + str += (cp & 63) + 128; + } + else if (0xd800 <= cp && cp <= 0xdfff) { + throw std::range_error("Invalid UTF-8 sequence"); + } + else if (cp <= 0xFFFF) { + str += (cp >> 12) + 224; + str += ((cp >> 6) & 63) + 128; + str += (cp & 63) + 128; + } + else if (cp <= 0x10FFFF) { + str += (cp >> 18) + 240; + str += ((cp >> 12) & 63) + 128; + str += ((cp >> 6) & 63) + 128; + str += (cp & 63) + 128; + } +} |