Allowed_Escapes[(unsigned int)c & 0xff]
JSONSL_API
-jsonsl_t jsonsl_new(size_t nlevels)
+jsonsl_t jsonsl_new(int nlevels)
{
struct jsonsl_st *jsn =
calloc(1, sizeof (*jsn) +
JSONSL_API
void jsonsl_reset(jsonsl_t jsn)
{
- size_t ii;
+ unsigned int ii;
jsn->tok_last = 0;
jsn->can_insert = 1;
jsn->pos = 0;
pctval = strtoul(c+1, NULL, 16);
*(c+3) = origc;
- *outp = pctval;
+ *outp = (char) pctval;
c += 2;
continue;
jsonsl_jpr_match_t
jsonsl_jpr_match(jsonsl_jpr_t jpr,
jsonsl_type_t parent_type,
- size_t parent_level,
+ unsigned int parent_level,
const char *key,
size_t nkey)
{
parent_state = jsn->stack + state->level - 1;
if (parent_state->type == JSONSL_T_LIST) {
- nkey = parent_state->nelem;
+ nkey = (size_t) parent_state->nelem;
}
*jmptable = 0;
#define UNESCAPE_BAIL(e,offset) \
*err = JSONSL_ERROR_##e; \
if (errat) { \
- *errat = (const char*)(c+ (ssize_t)(offset)); \
+ *errat = (const char*)(c+ (ptrdiff_t)(offset)); \
} \
return 0;
#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <wchar.h>
#endif /* JSONSL_USE_WCHAR */
/* Stolen from http-parser.h, and possibly others */
-#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
+#if defined(_WIN32) && !defined(__MINGW32__)
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
-
+#if !defined(_MSC_VER) || _MSC_VER<1400
typedef unsigned int size_t;
typedef int ssize_t;
+#endif
#else
#include <stdint.h>
#endif
/**
- * A state is a single level of the stack
+ * A state is a single level of the stack.
+ * Non-private data (i.e. the 'data' field, see the STATE_GENERIC section)
+ * will remain in tact until the item is popped.
+ *
+ * As a result, it means a parent state object may be accessed from a child
+ * object, (the parents fields will all be valid). This allows a user to create
+ * an ad-hoc hierarchy on top of the JSON one.
+ *
*/
struct jsonsl_state_st {
/**
size_t pos_begin;
/**
- * The position at which any immediate child was last POPped
+ * The position at which any immediate child was last POPped.
+ * Note that this field is only set when the item is popped.
*/
size_t pos_cur;
* variable, as this can technically be deduced from the lexer's
* level parameter (though the logic is not that simple)
*/
- size_t level;
+ unsigned int level;
/**
/**
* Put anything you want here. if JSONSL_STATE_USER_FIELDS is here, then
- * the macro expansion happens here
+ * the macro expansion happens here.
+ *
+ * You can use these fields to store hierarchical or 'tagging' information
+ * for specific objects.
+ *
+ * See the documentation above for the lifetime of the state object (i.e.
+ * if the private data points to allocated memory, it should be freed
+ * when the object is popped, as the state object will be re-used)
*/
#ifndef JSONSL_STATE_GENERIC
JSONSL_STATE_USER_FIELDS
/** Public, read-only */
/** This is the current level of the stack */
- size_t level;
+ unsigned int level;
/**
* This is the current position, relative to the beginning
char expecting;
char tok_last;
int can_insert;
- size_t levels_max;
+ unsigned int levels_max;
#ifndef JSONSL_NO_JPR
- unsigned int jpr_count;
+ size_t jpr_count;
jsonsl_jpr_t *jprs;
/* Root pointer for JPR matching information */
* @param nlevels maximum recursion depth
*/
JSONSL_API
-jsonsl_t jsonsl_new(size_t nlevels);
+jsonsl_t jsonsl_new(int nlevels);
/**
* Feeds data into the lexer.
* @param nkey - the length of the key. If the parent is an array (T_LIST), then
* this should be the current index.
*
+ * NOTE: The key of the child means any kind of associative data related to the
+ * element. Thus: <<< { "foo" : [ >>,
+ * the opening array's key is "foo".
+ *
* @return a status constant. This indicates whether a match was excluded, possible,
* or successful.
*/
JSONSL_API
jsonsl_jpr_match_t jsonsl_jpr_match(jsonsl_jpr_t jpr,
jsonsl_type_t parent_type,
- size_t parent_level,
+ unsigned int parent_level,
const char *key, size_t nkey);