17 #ifndef AWALI_JSON_UTILS_HH
18 #define AWALI_JSON_UTILS_HH
27 #define __SUPPRESS_UNUSED_WARNING__(a) (void)a;
42 std::ostream&
tabs(std::ostream& o,
int n) {
44 for(
int i=0; i<n; i++)
63 std::ostream&
js_formate(std::ostream& o, std::istream& i) {
96 o << std::endl <<
' ';
116 void check(std::istream& i,
char e, std::string oth=
"") {
121 }
while(c==
' ' || c==
'\n' || c==
'\t');
124 std::ostringstream os;
125 os <<
"parser expects ";
128 os << e <<
" gets " << c;
144 if(c!=
' ' && c!=
'\n' && c!=
'\t')
158 std::ostringstream o;
168 std::cerr <<
"found " << c;
171 case 'b': o <<
'\b'; std::cerr <<
"found \\b";
break;
172 case 'n': o <<
'\n';
break;
173 case 'f': o <<
'\f';
break;
174 case 'r': o <<
'\r';
break;
175 case 't': o <<
'\t';
break;
182 if(c1==
'0' && c2 ==
'0' && (c3 ==
'0' || c3 ==
'1')) {
183 c = (c3 ==
'1')?16:0;
184 if (
'0'<= c4 && c4 <=
'9')
186 else if (
'a'<= c4 && c4 <=
'f')
188 else if (
'A'<= c4 && c4 <=
'F')
192 "below 1F are supported, i.e., of the form \\u00YZ, where "
194 std::cerr <<
"found " << std::hex << (int) c;
199 "1F are supported, i.e., of the form \\u00YZ, where Y = 0 or "
221 case 'n' :
case 't': l=4;
break;
222 case 'f' : l=5;
break;
226 for(
int n=0; n<l; ++n) {
231 if(s!=
"true" && s!=
"none" && s!=
"null" && s!=
"false")
280 case 't':
case 'n' :
case 'f':
290 std::vector<std::string> res;
302 case '\b': o <<
"\\b";
break;
303 case '\f': o <<
"\\f";
break;
304 case '\n': o <<
"\\n";
break;
305 case '\r': o <<
"\\r";
break;
306 case '\t': o <<
"\\t";
break;
307 case '"': o <<
"\\\"";
break;
308 case '\\': o <<
"\\\\";
break;
310 if (
'\x00' <= c && c <=
'\x1f') {
312 << std::hex << std::setw(4) << std::setfill(
'0') << (int)c;
317 res[(
unsigned char) c] = o.str();
327 inline std::string
const&
escape(
char c) {
332 inline std::string
unescape(std::string
const& str) {
333 std::stringstream ss(str);
344 std::string
const & str)
353 inline std::string
escape (std::string
const& str) {
355 std::stringstream ss;
364 #undef __SUPPRESS_UNUSED_WARNING__
std::ostream & json(automaton_t aut, std::ostream &out)
static std::ostream & tabs(std::ostream &o, int n)
prints spaces
Definition: utils.hh:42
static char parsecst(std::istream &i)
Definition: utils.hh:216
static char peek(std::istream &i)
peeks the next character
Definition: utils.hh:139
static std::vector< std::string > const converter
Definition: utils.hh:322
static std::ostream & js_formate(std::ostream &o, std::istream &i)
formates a json file
Definition: utils.hh:63
static std::string parsestring(std::istream &i)
Definition: utils.hh:152
static int parseint(std::istream &i)
Definition: utils.hh:237
static std::string get_first_attr(std::istream &i)
Definition: utils.hh:245
static std::vector< std::string > init_converter()
Definition: utils.hh:289
static void parseignore(std::istream &i)
Definition: utils.hh:254
static void check(std::istream &i, char e, std::string oth="")
checks the next character
Definition: utils.hh:116
std::string const & escape(char c)
Definition: utils.hh:327
std::string unescape(std::string const &str)
Definition: utils.hh:332
std::ostream & escape_and_print(std::ostream &o, std::string const &str)
Definition: utils.hh:343
ATTRIBUTE_CONST int max(int a, int b)
Definition: arith.hh:54
ATTRIBUTE_CONST int min(int a, int b)
Definition: arith.hh:48
Main namespace of Awali.
Definition: ato.hh:22
Exceptions thrown during parsing.
Definition: parse_exception.hh:26
#define __SUPPRESS_UNUSED_WARNING__(a)
Definition: utils.hh:27