Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 1 | /* |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 2 | * $Id: json_tokener.h,v 1.10 2006/07/25 03:24:50 mclark Exp $ |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 3 | * |
Michael Clark | f6a6e48 | 2007-03-13 08:26:23 +0000 | [diff] [blame] | 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 5 | * Michael Clark <michael@metaparadigm.com> |
| 6 | * |
Michael Clark | f6a6e48 | 2007-03-13 08:26:23 +0000 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the MIT license. See COPYING for details. |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 9 | * |
| 10 | */ |
| 11 | |
| 12 | #ifndef _json_tokener_h_ |
| 13 | #define _json_tokener_h_ |
| 14 | |
Michael Clark | a327254 | 2008-01-26 01:10:47 +0000 | [diff] [blame] | 15 | #include <stddef.h> |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 16 | #include "json_object.h" |
| 17 | |
Michael Clark | aaec1ef | 2009-02-25 02:31:32 +0000 | [diff] [blame] | 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 22 | enum json_tokener_error { |
| 23 | json_tokener_success, |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 24 | json_tokener_continue, |
| 25 | json_tokener_error_depth, |
| 26 | json_tokener_error_parse_eof, |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 27 | json_tokener_error_parse_unexpected, |
| 28 | json_tokener_error_parse_null, |
| 29 | json_tokener_error_parse_boolean, |
| 30 | json_tokener_error_parse_number, |
| 31 | json_tokener_error_parse_array, |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 32 | json_tokener_error_parse_object_key_name, |
| 33 | json_tokener_error_parse_object_key_sep, |
| 34 | json_tokener_error_parse_object_value_sep, |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 35 | json_tokener_error_parse_string, |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 36 | json_tokener_error_parse_comment |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | enum json_tokener_state { |
| 40 | json_tokener_state_eatws, |
| 41 | json_tokener_state_start, |
| 42 | json_tokener_state_finish, |
| 43 | json_tokener_state_null, |
| 44 | json_tokener_state_comment_start, |
| 45 | json_tokener_state_comment, |
| 46 | json_tokener_state_comment_eol, |
| 47 | json_tokener_state_comment_end, |
| 48 | json_tokener_state_string, |
| 49 | json_tokener_state_string_escape, |
| 50 | json_tokener_state_escape_unicode, |
| 51 | json_tokener_state_boolean, |
| 52 | json_tokener_state_number, |
| 53 | json_tokener_state_array, |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 54 | json_tokener_state_array_add, |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 55 | json_tokener_state_array_sep, |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 56 | json_tokener_state_object_field_start, |
| 57 | json_tokener_state_object_field, |
| 58 | json_tokener_state_object_field_end, |
| 59 | json_tokener_state_object_value, |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 60 | json_tokener_state_object_value_add, |
Michael Clark | f6a6e48 | 2007-03-13 08:26:23 +0000 | [diff] [blame] | 61 | json_tokener_state_object_sep |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 64 | struct json_tokener_srec |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 65 | { |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 66 | enum json_tokener_state state, saved_state; |
| 67 | struct json_object *obj; |
| 68 | struct json_object *current; |
| 69 | char *obj_field_name; |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 72 | #define JSON_TOKENER_MAX_DEPTH 32 |
| 73 | |
| 74 | struct json_tokener |
| 75 | { |
| 76 | char *str; |
| 77 | struct printbuf *pb; |
| 78 | int depth, is_double, st_pos, char_offset; |
Michael Clark | c8f4a6e | 2007-12-07 02:44:24 +0000 | [diff] [blame] | 79 | ptrdiff_t err; |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 80 | unsigned int ucs_char; |
| 81 | char quote_char; |
| 82 | struct json_tokener_srec stack[JSON_TOKENER_MAX_DEPTH]; |
| 83 | }; |
| 84 | |
| 85 | extern const char* json_tokener_errors[]; |
| 86 | |
Michael Clark | 14862b1 | 2007-12-07 02:50:42 +0000 | [diff] [blame] | 87 | extern struct json_tokener* json_tokener_new(void); |
Michael Clark | a850f8e | 2007-03-13 08:26:26 +0000 | [diff] [blame] | 88 | extern void json_tokener_free(struct json_tokener *tok); |
| 89 | extern void json_tokener_reset(struct json_tokener *tok); |
| 90 | extern struct json_object* json_tokener_parse(char *str); |
| 91 | extern struct json_object* json_tokener_parse_ex(struct json_tokener *tok, |
| 92 | char *str, int len); |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 93 | |
Michael Clark | aaec1ef | 2009-02-25 02:31:32 +0000 | [diff] [blame] | 94 | #ifdef __cplusplus |
| 95 | } |
| 96 | #endif |
| 97 | |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 98 | #endif |