Annotation of parser3/src/lib/json/JSON_parser.h, revision 1.6

1.1       misha       1: /* See JSON_parser.c for copyright information and licensing. */
                      2: 
                      3: #ifndef JSON_PARSER_H
                      4: #define JSON_PARSER_H
                      5: 
                      6: /* JSON_parser.h */
                      7: 
1.5       moko        8: #include "pa_config_includes.h"
1.1       misha       9: 
                     10: /* Windows DLL stuff */
1.2       moko       11: #define JSON_PARSER_DLL_API 
1.1       misha      12: 
                     13: /* Determine the integer type use to parse non-floating point numbers */
1.6     ! moko       14: #if _MSC_VER
1.3       moko       15: typedef __int64 JSON_int_t;
                     16: #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%I64d"
                     17: #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%I64d"
                     18: #else 
1.1       misha      19: typedef long long JSON_int_t;
                     20: #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%lld"
                     21: #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%lld"
                     22: #endif
                     23: 
                     24: 
                     25: #ifdef __cplusplus
                     26: extern "C" {
                     27: #endif 
                     28: 
                     29: typedef enum 
                     30: {
                     31:     JSON_E_NONE = 0,
                     32:     JSON_E_INVALID_CHAR,
                     33:     JSON_E_INVALID_KEYWORD,
                     34:     JSON_E_INVALID_ESCAPE_SEQUENCE,
                     35:     JSON_E_INVALID_UNICODE_SEQUENCE,
                     36:     JSON_E_INVALID_NUMBER,
                     37:     JSON_E_NESTING_DEPTH_REACHED,
                     38:     JSON_E_UNBALANCED_COLLECTION,
                     39:     JSON_E_EXPECTED_KEY,
                     40:     JSON_E_EXPECTED_COLON,
                     41:     JSON_E_OUT_OF_MEMORY
                     42: } JSON_error;
                     43: 
                     44: typedef enum 
                     45: {
                     46:     JSON_T_NONE = 0,
                     47:     JSON_T_ARRAY_BEGIN,
                     48:     JSON_T_ARRAY_END,
                     49:     JSON_T_OBJECT_BEGIN,
                     50:     JSON_T_OBJECT_END,
                     51:     JSON_T_INTEGER,
                     52:     JSON_T_FLOAT,
                     53:     JSON_T_NULL,
                     54:     JSON_T_TRUE,
                     55:     JSON_T_FALSE,
                     56:     JSON_T_STRING,
                     57:     JSON_T_KEY,
                     58:     JSON_T_MAX
                     59: } JSON_type;
                     60: 
                     61: typedef struct JSON_value_struct {
                     62:     union {
                     63:         JSON_int_t integer_value;
                     64:         
                     65:         double float_value;
                     66:         
                     67:         struct {
                     68:             const char* value;
                     69:             size_t length;
                     70:         } str;
                     71:     } vu;
                     72: } JSON_value;
                     73: 
                     74: typedef struct JSON_parser_struct* JSON_parser;
                     75: 
                     76: /*! \brief JSON parser callback 
                     77: 
                     78:     \param ctx The pointer passed to new_JSON_parser.
                     79:     \param type An element of JSON_type but not JSON_T_NONE.    
                     80:     \param value A representation of the parsed value. This parameter is NULL for
                     81:         JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN, JSON_T_OBJECT_END,
                     82:         JSON_T_NULL, JSON_T_TRUE, and SON_T_FALSE. String values are always returned
                     83:         as zero-terminated C strings.
                     84: 
                     85:     \return Non-zero if parsing should continue, else zero.
                     86: */    
                     87: typedef int (*JSON_parser_callback)(void* ctx, int type, const struct JSON_value_struct* value);
                     88: 
                     89: 
                     90: /*! \brief The structure used to configure a JSON parser object 
                     91:     
                     92:     \param depth If negative, the parser can parse arbitrary levels of JSON, otherwise
                     93:         the depth is the limit
                     94:     \param Pointer to a callback. This parameter may be NULL. In this case the input is merely checked for validity.
                     95:     \param Callback context. This parameter may be NULL.
                     96:     \param depth. Specifies the levels of nested JSON to allow. Negative numbers yield unlimited nesting.
                     97:     \param allowComments. To allow C style comments in JSON, set to non-zero.
                     98:     \param handleFloatsManually. To decode floating point numbers manually set this parameter to non-zero.
                     99:     
                    100:     \return The parser object.
                    101: */
                    102: typedef struct {
                    103:     JSON_parser_callback     callback;
                    104:     void*                    callback_ctx;
                    105:     int                      depth;
                    106:     int                      allow_comments;
                    107:     int                      handle_floats_manually;
                    108: } JSON_config;
                    109: 
                    110: 
                    111: /*! \brief Initializes the JSON parser configuration structure to default values.
                    112: 
                    113:     The default configuration is
                    114:     - 127 levels of nested JSON (depends on JSON_PARSER_STACK_SIZE, see json_parser.c)
                    115:     - no parsing, just checking for JSON syntax
                    116:     - no comments
                    117: 
                    118:     \param config. Used to configure the parser.
                    119: */
                    120: JSON_PARSER_DLL_API void init_JSON_config(JSON_config* config);
                    121: 
                    122: /*! \brief Create a JSON parser object 
                    123:     
                    124:     \param config. Used to configure the parser. Set to NULL to use the default configuration. 
                    125:         See init_JSON_config
                    126:     
                    127:     \return The parser object.
                    128: */
                    129: JSON_PARSER_DLL_API extern JSON_parser new_JSON_parser(JSON_config* config);
                    130: 
                    131: /*! \brief Destroy a previously created JSON parser object. */
                    132: JSON_PARSER_DLL_API extern void delete_JSON_parser(JSON_parser jc);
                    133: 
                    134: /*! \brief Parse a character.
                    135: 
                    136:     \return Non-zero, if all characters passed to this function are part of are valid JSON.
                    137: */
                    138: JSON_PARSER_DLL_API extern int JSON_parser_char(JSON_parser jc, int next_char);
                    139: 
                    140: /*! \brief Finalize parsing.
                    141: 
                    142:     Call this method once after all input characters have been consumed.
                    143:     
                    144:     \return Non-zero, if all parsed characters are valid JSON, zero otherwise.
                    145: */
                    146: JSON_PARSER_DLL_API extern int JSON_parser_done(JSON_parser jc);
                    147: 
                    148: /*! \brief Determine if a given string is valid JSON white space 
                    149: 
                    150:     \return Non-zero if the string is valid, zero otherwise.
                    151: */
                    152: JSON_PARSER_DLL_API extern int JSON_parser_is_legal_white_space_string(const char* s);
                    153: 
                    154: /*! \brief Gets the last error that occurred during the use of JSON_parser.
                    155: 
                    156:     \return A value from the JSON_error enum.
                    157: */
                    158: JSON_PARSER_DLL_API extern int JSON_parser_get_last_error(JSON_parser jc);
                    159: 
                    160: 
                    161: 
                    162: #ifdef __cplusplus
                    163: }
                    164: #endif 
                    165:     
                    166: 
                    167: #endif /* JSON_PARSER_H */

E-mail: