Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string parseString() {
- auto str = appender!string();
- Next:
- switch(peekChar()) {
- case '"':
- getChar();
- break;
- case '\\':
- getChar();
- auto c = getChar();
- switch(c) {
- case '"': str.put('"'); break;
- case '\\': str.put('\\'); break;
- case '/': str.put('/'); break;
- case 'b': str.put('\b'); break;
- case 'f': str.put('\f'); break;
- case 'n': str.put('\n'); break;
- case 'r': str.put('\r'); break;
- case 't': str.put('\t'); break;
- case 'u':
- dchar val = 0;
- foreach_reverse(i; 0 .. 4) {
- auto hex = toupper(getChar());
- if(!isxdigit(hex)) error("Expecting hex character");
- val += (isdigit(hex) ? hex - '0' : hex - 'A') << (4 * i);
- }
- char[4] buf = void;
- str.put(toUTF8(buf, val)); // *****error here
- break;
- default:
- error(text("Invalid escape sequence '\\", c, "'."));
- }
- goto Next;
- default:
- auto c = getChar();
- appendJSONChar(&str, c, &error);
- goto Next;
- }
- return str.data;
- }
Add Comment
Please, Sign In to add comment