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