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

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

E-mail: