Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/json.h

    r7a80925 r5d749ad  
    11
    2 /* vim: set et ts=3 sw=3 sts=3 ft=c:
     2/* vim: set et ts=3 sw=3 ft=c:
    33 *
    4  * Copyright (C) 2012, 2013, 2014 James McLaughlin et al.  All rights reserved.
     4 * Copyright (C) 2012 James McLaughlin et al.  All rights reserved.
    55 * https://github.com/udp/json-parser
    66 *
     
    3636#endif
    3737
    38 #ifndef json_int_t
    39    #ifndef _MSC_VER
    40       #include <inttypes.h>
    41       #define json_int_t int64_t
    42    #else
    43       #define json_int_t __int64
    44    #endif
    45 #endif
    46 
    47 #include <stdlib.h>
    48 
    4938#ifdef __cplusplus
    5039
     
    6150   int settings;
    6251
    63    /* Custom allocator support (leave null to use malloc/free)
    64     */
    65 
    66    void * (* mem_alloc) (size_t, int zero, void * user_data);
    67    void (* mem_free) (void *, void * user_data);
    68 
    69    void * user_data;  /* will be passed to mem_alloc and mem_free */
    70 
    7152} json_settings;
    7253
    73 #define json_enable_comments  0x01
     54#define json_relaxed_commas 1
    7455
    7556typedef enum
     
    9778   {
    9879      int boolean;
    99       json_int_t integer;
     80      long long integer;
    10081      double dbl;
    10182
     
    11495         {
    11596            json_char * name;
    116             unsigned int name_length;
    117 
    11897            struct _json_value * value;
    11998
    12099         } * values;
    121 
    122          #if defined(__cplusplus) && __cplusplus >= 201103L
    123          decltype(values) begin () const
    124          {  return values;
    125          }
    126          decltype(values) end () const
    127          {  return values + length;
    128          }
    129          #endif
    130100
    131101      } object;
     
    135105         unsigned int length;
    136106         struct _json_value ** values;
    137 
    138          #if defined(__cplusplus) && __cplusplus >= 201103L
    139          decltype(values) begin () const
    140          {  return values;
    141          }
    142          decltype(values) end () const
    143          {  return values + length;
    144          }
    145          #endif
    146107
    147108      } array;
     
    202163         }
    203164
    204          inline operator json_int_t () const
    205          { 
    206             switch (type)
    207             {
    208                case json_integer:
    209                   return u.integer;
    210 
    211                case json_double:
    212                   return (json_int_t) u.dbl;
    213 
    214                default:
    215                   return 0;
    216             };
     165         inline operator long () const
     166         {  return u.integer;
    217167         }
    218168
    219169         inline operator bool () const
    220          { 
    221             if (type != json_boolean)
    222                return false;
    223 
    224             return u.boolean != 0;
    225          }
    226 
    227          inline operator double () const
    228          { 
    229             switch (type)
    230             {
    231                case json_integer:
    232                   return (double) u.integer;
    233 
    234                case json_double:
    235                   return u.dbl;
    236 
    237                default:
    238                   return 0;
    239             };
     170         {  return u.boolean != 0;
    240171         }
    241172
     
    244175} json_value;
    245176
    246 json_value * json_parse (const json_char * json,
    247                          size_t length);
     177json_value * json_parse
     178   (const json_char * json);
    248179
    249 #define json_error_max 128
    250 json_value * json_parse_ex (json_settings * settings,
    251                             const json_char * json,
    252                             size_t length,
    253                             char * error);
     180json_value * json_parse_ex
     181   (json_settings * settings, const json_char * json, char * error);
    254182
    255183void json_value_free (json_value *);
    256 
    257 
    258 /* Not usually necessary, unless you used a custom mem_alloc and now want to
    259  * use a custom mem_free.
    260  */
    261 void json_value_free_ex (json_settings * settings,
    262                          json_value *);
    263184
    264185
Note: See TracChangeset for help on using the changeset viewer.