Skip to content

Commit

Permalink
merge in latest from yajl proper
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmario committed Mar 19, 2010
1 parent 07dd794 commit 714421b
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 289 deletions.
20 changes: 10 additions & 10 deletions ext/api/yajl_common.h
@@ -1,22 +1,22 @@
/*
* Copyright 2007-2009, Lloyd Hilaiel.
*
* Copyright 2010, Lloyd Hilaiel.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
*
* 3. Neither the name of Lloyd Hilaiel nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -28,14 +28,14 @@
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/

#ifndef __YAJL_COMMON_H__
#define __YAJL_COMMON_H__

#ifdef __cplusplus
extern "C" {
#endif
#endif

#define YAJL_MAX_DEPTH 128

Expand All @@ -50,7 +50,7 @@ extern "C" {
# endif
#else
# define YAJL_API
#endif
#endif

/** pointer to a malloc function, supporting client overriding memory
* allocation routines */
Expand Down Expand Up @@ -80,6 +80,6 @@ typedef struct

#ifdef __cplusplus
}
#endif
#endif

#endif
52 changes: 26 additions & 26 deletions ext/api/yajl_gen.h
@@ -1,22 +1,22 @@
/*
* Copyright 2007-2009, Lloyd Hilaiel.
*
* Copyright 2010, Lloyd Hilaiel.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
*
* 3. Neither the name of Lloyd Hilaiel nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -28,7 +28,7 @@
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/

/**
* \file yajl_gen.h
Expand All @@ -42,7 +42,7 @@

#ifdef __cplusplus
extern "C" {
#endif
#endif
/** generator status codes */
typedef enum {
/** no error */
Expand All @@ -57,7 +57,7 @@ extern "C" {
* state */
yajl_gen_in_error_state,
/** A complete JSON document has been generated */
yajl_gen_generation_complete,
yajl_gen_generation_complete,
/** yajl_gen_double was passed an invalid floating point value
* (infinity or NaN). */
yajl_gen_invalid_number,
Expand Down Expand Up @@ -94,7 +94,7 @@ extern "C" {
*
* \returns an allocated handle on success, NULL on failure (bad params)
*/
yajl_gen YAJL_API yajl_gen_alloc(const yajl_gen_config * config,
YAJL_API yajl_gen yajl_gen_alloc(const yajl_gen_config * config,
const yajl_alloc_funcs * allocFuncs);

/** allocate a generator handle that will print to the specified
Expand All @@ -114,46 +114,46 @@ extern "C" {
*
* \returns an allocated handle on success, NULL on failure (bad params)
*/
yajl_gen YAJL_API yajl_gen_alloc2(yajl_print_t callback,
YAJL_API yajl_gen yajl_gen_alloc2(const yajl_print_t callback,
const yajl_gen_config * config,
const yajl_alloc_funcs * allocFuncs,
void * ctx);

/** free a generator handle */
void YAJL_API yajl_gen_free(yajl_gen handle);
/** free a generator handle */
YAJL_API void yajl_gen_free(yajl_gen handle);

yajl_gen_status YAJL_API yajl_gen_integer(yajl_gen hand, long int number);
YAJL_API yajl_gen_status yajl_gen_integer(yajl_gen hand, long int number);
/** generate a floating point number. number may not be infinity or
* NaN, as these have no representation in JSON. In these cases the
* generator will return 'yajl_gen_invalid_number' */
yajl_gen_status YAJL_API yajl_gen_double(yajl_gen hand, double number);
yajl_gen_status YAJL_API yajl_gen_number(yajl_gen hand,
YAJL_API yajl_gen_status yajl_gen_double(yajl_gen hand, double number);
YAJL_API yajl_gen_status yajl_gen_number(yajl_gen hand,
const char * num,
unsigned int len);
yajl_gen_status YAJL_API yajl_gen_string(yajl_gen hand,
YAJL_API yajl_gen_status yajl_gen_string(yajl_gen hand,
const unsigned char * str,
unsigned int len);
yajl_gen_status YAJL_API yajl_gen_null(yajl_gen hand);
yajl_gen_status YAJL_API yajl_gen_bool(yajl_gen hand, int boolean);
yajl_gen_status YAJL_API yajl_gen_map_open(yajl_gen hand);
yajl_gen_status YAJL_API yajl_gen_map_close(yajl_gen hand);
yajl_gen_status YAJL_API yajl_gen_array_open(yajl_gen hand);
yajl_gen_status YAJL_API yajl_gen_array_close(yajl_gen hand);
YAJL_API yajl_gen_status yajl_gen_null(yajl_gen hand);
YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean);
YAJL_API yajl_gen_status yajl_gen_map_open(yajl_gen hand);
YAJL_API yajl_gen_status yajl_gen_map_close(yajl_gen hand);
YAJL_API yajl_gen_status yajl_gen_array_open(yajl_gen hand);
YAJL_API yajl_gen_status yajl_gen_array_close(yajl_gen hand);

/** access the null terminated generator buffer. If incrementally
* outputing JSON, one should call yajl_gen_clear to clear the
* buffer. This allows stream generation. */
yajl_gen_status YAJL_API yajl_gen_get_buf(yajl_gen hand,
YAJL_API yajl_gen_status yajl_gen_get_buf(yajl_gen hand,
const unsigned char ** buf,
unsigned int * len);

/** clear yajl's output buffer, but maintain all internal generation
* state. This function will not "reset" the generator state, and is
* intended to enable incremental JSON outputing. */
void YAJL_API yajl_gen_clear(yajl_gen hand);
YAJL_API void yajl_gen_clear(yajl_gen hand);

#ifdef __cplusplus
}
#endif
#endif

#endif
56 changes: 35 additions & 21 deletions ext/api/yajl_parse.h
@@ -1,22 +1,22 @@
/*
* Copyright 2007-2009, Lloyd Hilaiel.
*
* Copyright 2010, Lloyd Hilaiel.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
*
* 3. Neither the name of Lloyd Hilaiel nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -28,7 +28,7 @@
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/

/**
* \file yajl_parse.h
Expand All @@ -42,7 +42,7 @@

#ifdef __cplusplus
extern "C" {
#endif
#endif
/** error codes returned from this interface */
typedef enum {
/** no error was encountered */
Expand All @@ -59,7 +59,7 @@ extern "C" {
} yajl_status;

/** attain a human readable, english, string for an error */
const char * YAJL_API yajl_status_to_string(yajl_status code);
YAJL_API const char * yajl_status_to_string(yajl_status code);

/** an opaque handle to a parser */
typedef struct yajl_handle_t * yajl_handle;
Expand Down Expand Up @@ -103,12 +103,12 @@ extern "C" {
int (* yajl_start_map)(void * ctx);
int (* yajl_map_key)(void * ctx, const unsigned char * key,
unsigned int stringLen);
int (* yajl_end_map)(void * ctx);
int (* yajl_end_map)(void * ctx);

int (* yajl_start_array)(void * ctx);
int (* yajl_end_array)(void * ctx);
int (* yajl_end_array)(void * ctx);
} yajl_callbacks;

/** configuration structure for the generator */
typedef struct {
/** if nonzero, javascript style comments will be allowed in
Expand All @@ -127,7 +127,7 @@ extern "C" {
* \param config configuration parameters for the parse.
* \param ctx a context pointer that will be passed to callbacks.
*/
yajl_handle YAJL_API yajl_alloc(const yajl_callbacks * callbacks,
YAJL_API yajl_handle yajl_alloc(const yajl_callbacks * callbacks,
const yajl_parser_config * config,
const yajl_alloc_funcs * allocFuncs,
void * ctx);
Expand All @@ -143,7 +143,7 @@ extern "C" {
* \param jsonText - a pointer to the UTF8 json text to be parsed
* \param jsonTextLength - the length, in bytes, of input text
*/
yajl_status YAJL_API yajl_parse(yajl_handle hand,
YAJL_API yajl_status yajl_parse(yajl_handle hand,
const unsigned char * jsonText,
unsigned int jsonTextLength);

Expand All @@ -156,27 +156,41 @@ extern "C" {
*
* \param hand - a handle to the json parser allocated with yajl_alloc
*/
yajl_status yajl_parse_complete(yajl_handle hand);

YAJL_API yajl_status yajl_parse_complete(yajl_handle hand);
/** get an error string describing the state of the
* parse.
*
* If verbose is non-zero, the message will include the JSON
* text where the error occured, along with an arrow pointing to
* the specific char.
*
* A dynamically allocated string will be returned which should
* be freed with yajl_free_error
* \returns A dynamically allocated string will be returned which should
* be freed with yajl_free_error
*/
unsigned char * YAJL_API yajl_get_error(yajl_handle hand, int verbose,
YAJL_API unsigned char * yajl_get_error(yajl_handle hand, int verbose,
const unsigned char * jsonText,
unsigned int jsonTextLength);

/**
* get the amount of data consumed from the last chunk passed to YAJL.
*
* In the case of a successful parse this can help you understand if
* the entire buffer was consumed (which will allow you to handle
* "junk at end of input".
*
* In the event an error is encountered during parsing, this function
* affords the client a way to get the offset into the most recent
* chunk where the error occured. 0 will be returned if no error
* was encountered.
*/
YAJL_API unsigned int yajl_get_bytes_consumed(yajl_handle hand);

/** free an error returned from yajl_get_error */
void YAJL_API yajl_free_error(yajl_handle hand, unsigned char * str);
YAJL_API void yajl_free_error(yajl_handle hand, unsigned char * str);

#ifdef __cplusplus
}
#endif
#endif

#endif

0 comments on commit 714421b

Please sign in to comment.