Changeset 989f431


Ignore:
Timestamp:
2015-02-22T16:15:28Z (5 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
ee170a1
Parents:
782a6ee
Message:

json_parse_first() which lets me find out where it stopped parsing, needed
for safe and proper stream parsing.

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/parson.c

    r782a6ee r989f431  
    769769}
    770770
    771 JSON_Value * json_parse_string(const char *string) {
     771JSON_Value * json_parse_first(const char *string, const char **end) {
     772    const char *pos;
     773    JSON_Value *ret;
     774
    772775    if (!string)
    773776        return NULL;
     
    775778    if (*string != '{' && *string != '[')
    776779        return NULL;
    777     return parse_value((const char**)&string, 0);
     780
     781    pos = string;
     782    ret = parse_value(&pos, 0);
     783    if (end)
     784        *end = pos;
     785
     786    return ret;
     787}
     788
     789JSON_Value * json_parse_string(const char *string) {
     790    return json_parse_first(string, NULL);
    778791}
    779792
  • lib/parson.h

    r782a6ee r989f431  
    5353};
    5454typedef int JSON_Status;
    55    
     55
    5656/* Parses first JSON value in a file, returns NULL in case of error */
    5757JSON_Value * json_parse_file(const char *filename);
     
    6060   returns NULL in case of error */
    6161JSON_Value * json_parse_file_with_comments(const char *filename);
    62    
     62
     63/*  Like json_parse_string, but *end is set to wherever it stopped parsing. */
     64JSON_Value * json_parse_first(const char *string, const char **end);
     65
    6366/*  Parses first JSON value in a string, returns NULL in case of error */
    6467JSON_Value * json_parse_string(const char *string);
Note: See TracChangeset for help on using the changeset viewer.