json 1.0.0 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +503 -0
- data/LICENSE +56 -0
- data/README.md +416 -0
- data/ext/json/ext/fbuffer/fbuffer.h +187 -0
- data/ext/json/ext/generator/depend +1 -0
- data/ext/json/ext/generator/extconf.rb +2 -7
- data/ext/json/ext/generator/generator.c +1312 -338
- data/ext/json/ext/generator/generator.h +177 -0
- data/ext/json/ext/parser/depend +1 -0
- data/ext/json/ext/parser/extconf.rb +28 -5
- data/ext/json/ext/parser/parser.c +1349 -689
- data/ext/json/ext/parser/parser.h +96 -0
- data/ext/json/ext/parser/parser.rl +644 -188
- data/ext/json/extconf.rb +3 -0
- data/json.gemspec +68 -0
- data/lib/json/add/bigdecimal.rb +58 -0
- data/lib/json/add/complex.rb +51 -0
- data/lib/json/add/core.rb +12 -0
- data/lib/json/add/date.rb +54 -0
- data/lib/json/add/date_time.rb +67 -0
- data/lib/json/add/exception.rb +49 -0
- data/lib/json/add/ostruct.rb +54 -0
- data/lib/json/add/range.rb +54 -0
- data/lib/json/add/rational.rb +49 -0
- data/lib/json/add/regexp.rb +48 -0
- data/lib/json/add/set.rb +48 -0
- data/lib/json/add/struct.rb +52 -0
- data/lib/json/add/symbol.rb +48 -0
- data/lib/json/add/time.rb +59 -0
- data/lib/json/common.rb +588 -74
- data/lib/json/ext.rb +3 -1
- data/lib/json/generic_object.rb +75 -0
- data/lib/json/pure/generator.rb +311 -119
- data/lib/json/pure/parser.rb +182 -55
- data/lib/json/pure.rb +5 -65
- data/lib/json/version.rb +2 -1
- data/lib/json.rb +583 -196
- metadata +78 -137
- data/CHANGES +0 -25
- data/GPL +0 -340
- data/README +0 -77
- data/Rakefile +0 -250
- data/TODO +0 -1
- data/VERSION +0 -1
- data/benchmarks/benchmark.txt +0 -133
- data/benchmarks/benchmark_generator.rb +0 -44
- data/benchmarks/benchmark_parser.rb +0 -22
- data/benchmarks/benchmark_rails.rb +0 -26
- data/bin/edit_json.rb +0 -11
- data/data/example.json +0 -1
- data/data/index.html +0 -37
- data/data/prototype.js +0 -2515
- data/ext/json/ext/generator/Makefile +0 -149
- data/ext/json/ext/generator/unicode.c +0 -184
- data/ext/json/ext/generator/unicode.h +0 -40
- data/ext/json/ext/parser/Makefile +0 -149
- data/ext/json/ext/parser/unicode.c +0 -156
- data/ext/json/ext/parser/unicode.h +0 -44
- data/install.rb +0 -26
- data/lib/json/Array.xpm +0 -21
- data/lib/json/FalseClass.xpm +0 -21
- data/lib/json/Hash.xpm +0 -21
- data/lib/json/Key.xpm +0 -73
- data/lib/json/NilClass.xpm +0 -21
- data/lib/json/Numeric.xpm +0 -28
- data/lib/json/String.xpm +0 -96
- data/lib/json/TrueClass.xpm +0 -21
- data/lib/json/editor.rb +0 -1207
- data/lib/json/json.xpm +0 -1499
- data/tests/fixtures/fail1.json +0 -1
- data/tests/fixtures/fail10.json +0 -1
- data/tests/fixtures/fail11.json +0 -1
- data/tests/fixtures/fail12.json +0 -1
- data/tests/fixtures/fail13.json +0 -1
- data/tests/fixtures/fail14.json +0 -1
- data/tests/fixtures/fail15.json +0 -1
- data/tests/fixtures/fail16.json +0 -1
- data/tests/fixtures/fail17.json +0 -1
- data/tests/fixtures/fail19.json +0 -1
- data/tests/fixtures/fail2.json +0 -1
- data/tests/fixtures/fail20.json +0 -1
- data/tests/fixtures/fail21.json +0 -1
- data/tests/fixtures/fail22.json +0 -1
- data/tests/fixtures/fail23.json +0 -1
- data/tests/fixtures/fail24.json +0 -1
- data/tests/fixtures/fail25.json +0 -1
- data/tests/fixtures/fail26.json +0 -1
- data/tests/fixtures/fail27.json +0 -2
- data/tests/fixtures/fail28.json +0 -2
- data/tests/fixtures/fail3.json +0 -1
- data/tests/fixtures/fail4.json +0 -1
- data/tests/fixtures/fail5.json +0 -1
- data/tests/fixtures/fail6.json +0 -1
- data/tests/fixtures/fail7.json +0 -1
- data/tests/fixtures/fail8.json +0 -1
- data/tests/fixtures/fail9.json +0 -1
- data/tests/fixtures/pass1.json +0 -56
- data/tests/fixtures/pass18.json +0 -1
- data/tests/fixtures/pass2.json +0 -1
- data/tests/fixtures/pass3.json +0 -6
- data/tests/runner.rb +0 -24
- data/tests/test_json.rb +0 -235
- data/tests/test_json_addition.rb +0 -94
- data/tests/test_json_fixtures.rb +0 -30
- data/tests/test_json_generate.rb +0 -81
- data/tests/test_json_unicode.rb +0 -55
- data/tools/fuzz.rb +0 -133
- data/tools/server.rb +0 -62
@@ -0,0 +1,96 @@
|
|
1
|
+
#ifndef _PARSER_H_
|
2
|
+
#define _PARSER_H_
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
|
6
|
+
#ifndef HAVE_RUBY_RE_H
|
7
|
+
#include "re.h"
|
8
|
+
#endif
|
9
|
+
|
10
|
+
#ifdef HAVE_RUBY_ST_H
|
11
|
+
#include "ruby/st.h"
|
12
|
+
#else
|
13
|
+
#include "st.h"
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#ifndef MAYBE_UNUSED
|
17
|
+
# define MAYBE_UNUSED(x) x
|
18
|
+
#endif
|
19
|
+
|
20
|
+
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
|
21
|
+
|
22
|
+
/* unicode */
|
23
|
+
|
24
|
+
typedef unsigned long UTF32; /* at least 32 bits */
|
25
|
+
typedef unsigned short UTF16; /* at least 16 bits */
|
26
|
+
typedef unsigned char UTF8; /* typically 8 bits */
|
27
|
+
|
28
|
+
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
|
29
|
+
#define UNI_SUR_HIGH_START (UTF32)0xD800
|
30
|
+
#define UNI_SUR_HIGH_END (UTF32)0xDBFF
|
31
|
+
#define UNI_SUR_LOW_START (UTF32)0xDC00
|
32
|
+
#define UNI_SUR_LOW_END (UTF32)0xDFFF
|
33
|
+
|
34
|
+
typedef struct JSON_ParserStruct {
|
35
|
+
VALUE Vsource;
|
36
|
+
char *source;
|
37
|
+
long len;
|
38
|
+
char *memo;
|
39
|
+
VALUE create_id;
|
40
|
+
int max_nesting;
|
41
|
+
int allow_nan;
|
42
|
+
int parsing_name;
|
43
|
+
int symbolize_names;
|
44
|
+
int freeze;
|
45
|
+
VALUE object_class;
|
46
|
+
VALUE array_class;
|
47
|
+
VALUE decimal_class;
|
48
|
+
int create_additions;
|
49
|
+
VALUE match_string;
|
50
|
+
FBuffer *fbuffer;
|
51
|
+
} JSON_Parser;
|
52
|
+
|
53
|
+
#define GET_PARSER \
|
54
|
+
GET_PARSER_INIT; \
|
55
|
+
if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
|
56
|
+
#define GET_PARSER_INIT \
|
57
|
+
JSON_Parser *json; \
|
58
|
+
TypedData_Get_Struct(self, JSON_Parser, &JSON_Parser_type, json)
|
59
|
+
|
60
|
+
#define MinusInfinity "-Infinity"
|
61
|
+
#define EVIL 0x666
|
62
|
+
|
63
|
+
static UTF32 unescape_unicode(const unsigned char *p);
|
64
|
+
static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
|
65
|
+
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
66
|
+
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
67
|
+
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
|
68
|
+
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
|
69
|
+
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
70
|
+
static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int symbolize);
|
71
|
+
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
|
72
|
+
static VALUE convert_encoding(VALUE source);
|
73
|
+
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
|
74
|
+
static VALUE cParser_parse(VALUE self);
|
75
|
+
static void JSON_mark(void *json);
|
76
|
+
static void JSON_free(void *json);
|
77
|
+
static VALUE cJSON_parser_s_allocate(VALUE klass);
|
78
|
+
static VALUE cParser_source(VALUE self);
|
79
|
+
#ifndef ZALLOC
|
80
|
+
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|
81
|
+
static inline void *ruby_zalloc(size_t n)
|
82
|
+
{
|
83
|
+
void *p = ruby_xmalloc(n);
|
84
|
+
memset(p, 0, n);
|
85
|
+
return p;
|
86
|
+
}
|
87
|
+
#endif
|
88
|
+
#ifdef TypedData_Make_Struct
|
89
|
+
static const rb_data_type_t JSON_Parser_type;
|
90
|
+
#define NEW_TYPEDDATA_WRAPPER 1
|
91
|
+
#else
|
92
|
+
#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, JSON_free, json)
|
93
|
+
#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
|
94
|
+
#endif
|
95
|
+
|
96
|
+
#endif
|