| 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 <stdint.h> |
| 10 | |
| 11 | #include "string_buffer.hpp" |
| 12 | #include "string_ref.hpp" |
| 13 | #include "string_util.hpp" |
| 14 | |
| 15 | #ifndef DENA_ESCAPE_HPP |
| 16 | #define DENA_ESCAPE_HPP |
| 17 | |
| 18 | namespace dena { |
| 19 | |
| 20 | void escape_string(char *& wp, const char *start, const char *finish); |
| 21 | void escape_string(string_buffer& ar, const char *start, const char *finish); |
| 22 | bool unescape_string(char *& wp, const char *start, const char *finish); |
| 23 | /* unescaped_string() works even if wp == start */ |
| 24 | bool unescape_string(string_buffer& ar, const char *start, const char *finish); |
| 25 | |
| 26 | uint32_t read_ui32(char *& start, char *finish); |
| 27 | void write_ui32(string_buffer& buf, uint32_t v); |
| 28 | void write_ui64(string_buffer& buf, uint64_t v); |
| 29 | |
| 30 | inline bool |
| 31 | is_null_expression(const char *start, const char *finish) |
| 32 | { |
| 33 | return (finish == start + 1 && start[0] == 0); |
| 34 | } |
| 35 | |
| 36 | inline void |
| 37 | read_token(char *& start, char *finish) |
| 38 | { |
| 39 | char *const p = memchr_char(start, '\t', finish - start); |
| 40 | if (p == 0) { |
| 41 | start = finish; |
| 42 | } else { |
| 43 | start = p; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | inline void |
| 48 | skip_token_delim_fold(char *& start, char *finish) |
| 49 | { |
| 50 | while (start != finish && start[0] == '\t') { |
| 51 | ++start; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | inline void |
| 56 | skip_one(char *& start, char *finish) |
| 57 | { |
| 58 | if (start != finish) { |
| 59 | ++start; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | }; |
| 64 | |
| 65 | #endif |
| 66 | |
| 67 | |