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
18namespace dena {
19
20void escape_string(char *& wp, const char *start, const char *finish);
21void escape_string(string_buffer& ar, const char *start, const char *finish);
22bool unescape_string(char *& wp, const char *start, const char *finish);
23 /* unescaped_string() works even if wp == start */
24bool unescape_string(string_buffer& ar, const char *start, const char *finish);
25
26uint32_t read_ui32(char *& start, char *finish);
27void write_ui32(string_buffer& buf, uint32_t v);
28void write_ui64(string_buffer& buf, uint64_t v);
29
30inline bool
31is_null_expression(const char *start, const char *finish)
32{
33 return (finish == start + 1 && start[0] == 0);
34}
35
36inline void
37read_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
47inline void
48skip_token_delim_fold(char *& start, char *finish)
49{
50 while (start != finish && start[0] == '\t') {
51 ++start;
52 }
53}
54
55inline void
56skip_one(char *& start, char *finish)
57{
58 if (start != finish) {
59 ++start;
60 }
61}
62
63};
64
65#endif
66
67