2007-03-13 08:26:18 +00:00
|
|
|
/*
|
2007-03-13 08:26:26 +00:00
|
|
|
* $Id: json_tokener.h,v 1.10 2006/07/25 03:24:50 mclark Exp $
|
2007-03-13 08:26:18 +00:00
|
|
|
*
|
2007-03-13 08:26:23 +00:00
|
|
|
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
|
2007-03-13 08:26:18 +00:00
|
|
|
* Michael Clark <michael@metaparadigm.com>
|
|
|
|
|
*
|
2007-03-13 08:26:23 +00:00
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the MIT license. See COPYING for details.
|
2007-03-13 08:26:18 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _json_tokener_h_
|
|
|
|
|
#define _json_tokener_h_
|
|
|
|
|
|
2008-01-26 01:10:47 +00:00
|
|
|
#include <stddef.h>
|
2007-03-13 08:26:18 +00:00
|
|
|
#include "json_object.h"
|
|
|
|
|
|
|
|
|
|
enum json_tokener_error {
|
|
|
|
|
json_tokener_success,
|
2007-03-13 08:26:26 +00:00
|
|
|
json_tokener_continue,
|
|
|
|
|
json_tokener_error_depth,
|
|
|
|
|
json_tokener_error_parse_eof,
|
2007-03-13 08:26:18 +00:00
|
|
|
json_tokener_error_parse_unexpected,
|
|
|
|
|
json_tokener_error_parse_null,
|
|
|
|
|
json_tokener_error_parse_boolean,
|
|
|
|
|
json_tokener_error_parse_number,
|
|
|
|
|
json_tokener_error_parse_array,
|
2007-03-13 08:26:26 +00:00
|
|
|
json_tokener_error_parse_object_key_name,
|
|
|
|
|
json_tokener_error_parse_object_key_sep,
|
|
|
|
|
json_tokener_error_parse_object_value_sep,
|
2007-03-13 08:26:18 +00:00
|
|
|
json_tokener_error_parse_string,
|
2007-03-13 08:26:26 +00:00
|
|
|
json_tokener_error_parse_comment
|
2007-03-13 08:26:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum json_tokener_state {
|
|
|
|
|
json_tokener_state_eatws,
|
|
|
|
|
json_tokener_state_start,
|
|
|
|
|
json_tokener_state_finish,
|
|
|
|
|
json_tokener_state_null,
|
|
|
|
|
json_tokener_state_comment_start,
|
|
|
|
|
json_tokener_state_comment,
|
|
|
|
|
json_tokener_state_comment_eol,
|
|
|
|
|
json_tokener_state_comment_end,
|
|
|
|
|
json_tokener_state_string,
|
|
|
|
|
json_tokener_state_string_escape,
|
|
|
|
|
json_tokener_state_escape_unicode,
|
|
|
|
|
json_tokener_state_boolean,
|
|
|
|
|
json_tokener_state_number,
|
|
|
|
|
json_tokener_state_array,
|
2007-03-13 08:26:26 +00:00
|
|
|
json_tokener_state_array_add,
|
2007-03-13 08:26:18 +00:00
|
|
|
json_tokener_state_array_sep,
|
|
|
|
|
json_tokener_state_object_field_start,
|
|
|
|
|
json_tokener_state_object_field,
|
|
|
|
|
json_tokener_state_object_field_end,
|
|
|
|
|
json_tokener_state_object_value,
|
2007-03-13 08:26:26 +00:00
|
|
|
json_tokener_state_object_value_add,
|
2007-03-13 08:26:23 +00:00
|
|
|
json_tokener_state_object_sep
|
2007-03-13 08:26:18 +00:00
|
|
|
};
|
|
|
|
|
|
2007-03-13 08:26:26 +00:00
|
|
|
struct json_tokener_srec
|
|
|
|
|
{
|
|
|
|
|
enum json_tokener_state state, saved_state;
|
|
|
|
|
struct json_object *obj;
|
|
|
|
|
struct json_object *current;
|
|
|
|
|
char *obj_field_name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define JSON_TOKENER_MAX_DEPTH 32
|
|
|
|
|
|
2007-03-13 08:26:18 +00:00
|
|
|
struct json_tokener
|
|
|
|
|
{
|
2007-03-13 08:26:26 +00:00
|
|
|
char *str;
|
2007-03-13 08:26:18 +00:00
|
|
|
struct printbuf *pb;
|
2007-03-13 08:26:26 +00:00
|
|
|
int depth, is_double, st_pos, char_offset;
|
2007-12-07 02:44:24 +00:00
|
|
|
ptrdiff_t err;
|
2007-03-13 08:26:26 +00:00
|
|
|
unsigned int ucs_char;
|
|
|
|
|
char quote_char;
|
|
|
|
|
struct json_tokener_srec stack[JSON_TOKENER_MAX_DEPTH];
|
2007-03-13 08:26:18 +00:00
|
|
|
};
|
|
|
|
|
|
2007-03-13 08:26:26 +00:00
|
|
|
extern const char* json_tokener_errors[];
|
|
|
|
|
|
2007-12-07 02:50:42 +00:00
|
|
|
extern struct json_tokener* json_tokener_new(void);
|
2007-03-13 08:26:26 +00:00
|
|
|
extern void json_tokener_free(struct json_tokener *tok);
|
|
|
|
|
extern void json_tokener_reset(struct json_tokener *tok);
|
|
|
|
|
extern struct json_object* json_tokener_parse(char *str);
|
|
|
|
|
extern struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
|
|
|
|
|
char *str, int len);
|
2007-03-13 08:26:18 +00:00
|
|
|
|
|
|
|
|
#endif
|