[ovs-dev] [PATCH 08/13] json: Export function to parse an individual JSON string.

Jesse Gross jesse at nicira.com
Mon Jan 25 22:04:53 UTC 2010


On Mon, Jan 25, 2010 at 1:18 PM, Ben Pfaff <blp at nicira.com> wrote:

> The JSON syntax for strings is very reasonable.  An upcoming commit will
> have a need for a string parser, so make the JSON string parser available
> for that.
>
> Also, this change improves the error message for strings that end in the
> middle of a \u sequence, so update the tests to match.
>

 Looks good, one comment:

-static void
> -json_lex_string(struct json_parser *p)
> +bool
> +json_string_unescape(const char *in, size_t in_len, char **outp)
>  {
> -    struct json_token token;
> -    const char *cp;
> -    struct ds s;
> +    const char *end = in + in_len;
> +    bool ok = false;
> +    struct ds out;
>
> -    cp = ds_cstr(&p->buffer);
> -    if (!strchr(cp, '\\')) {
> -        token.type = T_STRING;
> -        token.u.string = cp;
> -        json_parser_input(p, &token);
> -        return;
> +    ds_init(&out);
> +    ds_reserve(&out, strlen(in));
>

Shouldn't strlen(in) be in_len?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20100125/53a0e073/attachment-0003.html>


More information about the dev mailing list