Ruby
2.0.0p247(2013-06-27revision41674)
|
00001 #ifndef _PARSER_H_ 00002 #define _PARSER_H_ 00003 00004 #include "ruby.h" 00005 00006 #ifndef HAVE_RUBY_RE_H 00007 #include "re.h" 00008 #endif 00009 00010 #ifdef HAVE_RUBY_ST_H 00011 #include "ruby/st.h" 00012 #else 00013 #include "st.h" 00014 #endif 00015 00016 #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key)) 00017 00018 /* unicode */ 00019 00020 typedef unsigned long UTF32; /* at least 32 bits */ 00021 typedef unsigned short UTF16; /* at least 16 bits */ 00022 typedef unsigned char UTF8; /* typically 8 bits */ 00023 00024 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD 00025 #define UNI_SUR_HIGH_START (UTF32)0xD800 00026 #define UNI_SUR_HIGH_END (UTF32)0xDBFF 00027 #define UNI_SUR_LOW_START (UTF32)0xDC00 00028 #define UNI_SUR_LOW_END (UTF32)0xDFFF 00029 00030 typedef struct JSON_ParserStruct { 00031 VALUE Vsource; 00032 char *source; 00033 long len; 00034 char *memo; 00035 VALUE create_id; 00036 int max_nesting; 00037 int current_nesting; 00038 int allow_nan; 00039 int parsing_name; 00040 int symbolize_names; 00041 int quirks_mode; 00042 VALUE object_class; 00043 VALUE array_class; 00044 int create_additions; 00045 VALUE match_string; 00046 FBuffer *fbuffer; 00047 } JSON_Parser; 00048 00049 #define GET_PARSER \ 00050 GET_PARSER_INIT; \ 00051 if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance") 00052 #define GET_PARSER_INIT \ 00053 JSON_Parser *json; \ 00054 Data_Get_Struct(self, JSON_Parser, json) 00055 00056 #define MinusInfinity "-Infinity" 00057 #define EVIL 0x666 00058 00059 static UTF32 unescape_unicode(const unsigned char *p); 00060 static int convert_UTF32_to_UTF8(char *buf, UTF32 ch); 00061 static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result); 00062 static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result); 00063 static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result); 00064 static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result); 00065 static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result); 00066 static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd); 00067 static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result); 00068 static VALUE convert_encoding(VALUE source); 00069 static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self); 00070 static VALUE cParser_parse(VALUE self); 00071 static JSON_Parser *JSON_allocate(); 00072 static void JSON_mark(JSON_Parser *json); 00073 static void JSON_free(JSON_Parser *json); 00074 static VALUE cJSON_parser_s_allocate(VALUE klass); 00075 static VALUE cParser_source(VALUE self); 00076 00077 #endif 00078