10 #ifdef HAVE_RUBY_ENCODING_H
11 #include "ruby/encoding.h"
12 #define FORCE_UTF8(obj) ((obj) = rb_enc_associate(rb_str_dup(obj), rb_utf8_encoding()))
14 #define FORCE_UTF8(obj)
22 #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
26 typedef unsigned long UTF32; /* at least 32 bits */
27 typedef unsigned short UTF16; /* at least 16 bits */
28 typedef unsigned char UTF8; /* typically 8 bits */
30 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
31 #define UNI_SUR_HIGH_START (UTF32)0xD800
32 #define UNI_SUR_HIGH_END (UTF32)0xDBFF
33 #define UNI_SUR_LOW_START (UTF32)0xDC00
34 #define UNI_SUR_LOW_END (UTF32)0xDFFF
36 typedef struct JSON_ParserStruct {
56 if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
57 #define GET_PARSER_INIT \
59 Data_Get_Struct(self, JSON_Parser, json)
61 #define MinusInfinity "-Infinity"
64 static UTF32 unescape_unicode(const unsigned char *p);
65 static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
66 static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
67 static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result);
68 static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
69 static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
70 static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result);
71 static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd);
72 static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
73 static VALUE convert_encoding(VALUE source);
74 static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
75 static VALUE cParser_parse(VALUE self);
76 static JSON_Parser *JSON_allocate();
77 static void JSON_mark(JSON_Parser *json);
78 static void JSON_free(JSON_Parser *json);
79 static VALUE cJSON_parser_s_allocate(VALUE klass);
80 static VALUE cParser_source(VALUE self);