You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

json_tokener.h 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * $Id: json_tokener.h,v 1.10 2006/07/25 03:24:50 mclark Exp $
  3. *
  4. * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
  5. * Michael Clark <michael@metaparadigm.com>
  6. *
  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.
  9. *
  10. */
  11. #ifndef _json_tokener_h_
  12. #define _json_tokener_h_
  13. #include <stddef.h>
  14. #include "json_object.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. enum json_tokener_error {
  19. json_tokener_success,
  20. json_tokener_continue,
  21. json_tokener_error_depth,
  22. json_tokener_error_parse_eof,
  23. json_tokener_error_parse_unexpected,
  24. json_tokener_error_parse_null,
  25. json_tokener_error_parse_boolean,
  26. json_tokener_error_parse_number,
  27. json_tokener_error_parse_array,
  28. json_tokener_error_parse_object_key_name,
  29. json_tokener_error_parse_object_key_sep,
  30. json_tokener_error_parse_object_value_sep,
  31. json_tokener_error_parse_string,
  32. json_tokener_error_parse_comment
  33. };
  34. enum json_tokener_state {
  35. json_tokener_state_eatws,
  36. json_tokener_state_start,
  37. json_tokener_state_finish,
  38. json_tokener_state_null,
  39. json_tokener_state_comment_start,
  40. json_tokener_state_comment,
  41. json_tokener_state_comment_eol,
  42. json_tokener_state_comment_end,
  43. json_tokener_state_string,
  44. json_tokener_state_string_escape,
  45. json_tokener_state_escape_unicode,
  46. json_tokener_state_boolean,
  47. json_tokener_state_number,
  48. json_tokener_state_array,
  49. json_tokener_state_array_add,
  50. json_tokener_state_array_sep,
  51. json_tokener_state_object_field_start,
  52. json_tokener_state_object_field,
  53. json_tokener_state_object_field_end,
  54. json_tokener_state_object_value,
  55. json_tokener_state_object_value_add,
  56. json_tokener_state_object_sep
  57. };
  58. struct json_tokener_srec
  59. {
  60. enum json_tokener_state state, saved_state;
  61. struct json_object *obj;
  62. struct json_object *current;
  63. char *obj_field_name;
  64. };
  65. #define JSON_TOKENER_MAX_DEPTH 32
  66. struct json_tokener
  67. {
  68. char *str;
  69. struct printbuf *pb;
  70. int depth, is_double, st_pos, char_offset;
  71. enum json_tokener_error err;
  72. unsigned int ucs_char;
  73. char quote_char;
  74. struct json_tokener_srec stack[JSON_TOKENER_MAX_DEPTH];
  75. };
  76. extern const char* json_tokener_errors[];
  77. extern struct json_tokener* json_tokener_new(void);
  78. extern void json_tokener_free(struct json_tokener *tok);
  79. extern void json_tokener_reset(struct json_tokener *tok);
  80. extern struct json_object* json_tokener_parse(const char *str);
  81. extern struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error);
  82. extern struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
  83. const char *str, int len);
  84. #ifdef __cplusplus
  85. }
  86. #endif
  87. #endif