| 1 | |
| 2 | // vim:sw=2:ai |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved. |
| 6 | * See COPYRIGHT.txt for details. |
| 7 | */ |
| 8 | |
| 9 | #include "string_buffer.hpp" |
| 10 | #include "string_ref.hpp" |
| 11 | #include "string_util.hpp" |
| 12 | |
| 13 | #ifndef DENA_ESCAPE_HPP |
| 14 | #define DENA_ESCAPE_HPP |
| 15 | |
| 16 | namespace dena { |
| 17 | |
| 18 | void escape_string(char *& wp, const char *start, const char *finish); |
| 19 | void escape_string(string_buffer& ar, const char *start, const char *finish); |
| 20 | bool unescape_string(char *& wp, const char *start, const char *finish); |
| 21 | /* unescaped_string() works even if wp == start */ |
| 22 | bool unescape_string(string_buffer& ar, const char *start, const char *finish); |
| 23 | |
| 24 | uint32 read_ui32(char *& start, char *finish); |
| 25 | void write_ui32(string_buffer& buf, uint32 v); |
| 26 | void write_ui64(string_buffer& buf, uint64 v); |
| 27 | |
| 28 | inline bool |
| 29 | is_null_expression(const char *start, const char *finish) |
| 30 | { |
| 31 | return (finish == start + 1 && start[0] == 0); |
| 32 | } |
| 33 | |
| 34 | inline void |
| 35 | read_token(char *& start, char *finish) |
| 36 | { |
| 37 | char *const p = memchr_char(start, '\t', finish - start); |
| 38 | if (p == 0) { |
| 39 | start = finish; |
| 40 | } else { |
| 41 | start = p; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | inline void |
| 46 | skip_token_delim_fold(char *& start, char *finish) |
| 47 | { |
| 48 | while (start != finish && start[0] == '\t') { |
| 49 | ++start; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | inline void |
| 54 | skip_one(char *& start, char *finish) |
| 55 | { |
| 56 | if (start != finish) { |
| 57 | ++start; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | }; |
| 62 | |
| 63 | #endif |
| 64 | |
| 65 | |