/*
- * Copyright (c) 2009, 2010, 2011, 2012, 2014 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return ok;
}
+void
+json_string_escape(const char *in, struct ds *out)
+{
+ struct json json = {
+ .type = JSON_STRING,
+ .u.string = CONST_CAST(char *, in),
+ };
+ json_to_ds(&json, 0, out);
+}
+
static void
json_parser_input_string(struct json_parser *p, const char *s)
{
/*
- * Copyright (c) 2009, 2010 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/* JSON string formatting operations. */
bool json_string_unescape(const char *in, size_t in_len, char **outp);
+void json_string_escape(const char *in, struct ds *out);
#ifdef __cplusplus
}
*startp = *n_bitsp = 0;
}
-static void
-expr_format_string(const char *s, struct ds *ds)
-{
- struct json json = {
- .type = JSON_STRING,
- .u.string = CONST_CAST(char *, s),
- };
- json_to_ds(&json, 0, ds);
-}
-
static void
expr_format_cmp(const struct expr *e, struct ds *s)
{
if (!e->cmp.symbol->width) {
ds_put_format(s, "%s %s ", e->cmp.symbol->name,
expr_relop_to_string(e->cmp.relop));
- expr_format_string(e->cmp.string, s);
+ json_string_escape(e->cmp.string, s);
return;
}
}
}
-static void
-lex_token_format_string(const char *s, struct ds *ds)
-{
- struct json json = {
- .type = JSON_STRING,
- .u.string = CONST_CAST(char *, s),
- };
- json_to_ds(&json, 0, ds);
-}
-
/* Appends a string representation of 'token' to 's', in a format that can be
* losslessly parsed back by the lexer. (LEX_T_END and LEX_T_ERROR can't be
* parsed back.) */
case LEX_T_ERROR:
ds_put_cstr(s, "error(");
- lex_token_format_string(token->s, s);
+ json_string_escape(token->s, s);
ds_put_char(s, ')');
break;
case LEX_T_STRING:
- lex_token_format_string(token->s, s);
- break;
-
+ json_string_escape(token->s, s);
break;
case LEX_T_INTEGER: