json 1.8.3 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +5 -5
  2. data/{CHANGES → CHANGES.md} +244 -93
  3. data/{COPYING-json-jruby → LICENSE} +5 -6
  4. data/{README.rdoc → README.md} +202 -135
  5. data/VERSION +1 -1
  6. data/ext/json/ext/fbuffer/fbuffer.h +0 -3
  7. data/ext/json/ext/generator/generator.c +264 -114
  8. data/ext/json/ext/generator/generator.h +12 -4
  9. data/ext/json/ext/parser/extconf.rb +29 -0
  10. data/ext/json/ext/parser/parser.c +3002 -1880
  11. data/ext/json/ext/parser/parser.h +10 -6
  12. data/ext/json/ext/parser/parser.rl +230 -192
  13. data/ext/json/extconf.rb +1 -1
  14. data/json.gemspec +0 -0
  15. data/lib/json/add/bigdecimal.rb +3 -2
  16. data/lib/json/add/complex.rb +4 -4
  17. data/lib/json/add/core.rb +1 -0
  18. data/lib/json/add/date.rb +1 -1
  19. data/lib/json/add/date_time.rb +1 -1
  20. data/lib/json/add/exception.rb +1 -1
  21. data/lib/json/add/ostruct.rb +3 -3
  22. data/lib/json/add/range.rb +1 -1
  23. data/lib/json/add/rational.rb +3 -3
  24. data/lib/json/add/regexp.rb +3 -3
  25. data/lib/json/add/set.rb +29 -0
  26. data/lib/json/add/struct.rb +1 -1
  27. data/lib/json/add/symbol.rb +1 -1
  28. data/lib/json/add/time.rb +1 -1
  29. data/lib/json/common.rb +381 -162
  30. data/lib/json/ext.rb +0 -6
  31. data/lib/json/generic_object.rb +5 -4
  32. data/lib/json/pure/generator.rb +83 -126
  33. data/lib/json/pure/parser.rb +63 -85
  34. data/lib/json/pure.rb +2 -8
  35. data/lib/json/version.rb +2 -1
  36. data/lib/json.rb +550 -29
  37. metadata +23 -132
  38. data/.gitignore +0 -16
  39. data/.travis.yml +0 -26
  40. data/COPYING +0 -58
  41. data/GPL +0 -340
  42. data/Gemfile +0 -10
  43. data/README-json-jruby.markdown +0 -33
  44. data/Rakefile +0 -412
  45. data/TODO +0 -1
  46. data/data/example.json +0 -1
  47. data/data/index.html +0 -38
  48. data/data/prototype.js +0 -4184
  49. data/diagrams/.keep +0 -0
  50. data/install.rb +0 -23
  51. data/java/src/json/ext/ByteListTranscoder.java +0 -167
  52. data/java/src/json/ext/Generator.java +0 -444
  53. data/java/src/json/ext/GeneratorMethods.java +0 -232
  54. data/java/src/json/ext/GeneratorService.java +0 -43
  55. data/java/src/json/ext/GeneratorState.java +0 -543
  56. data/java/src/json/ext/OptionsReader.java +0 -114
  57. data/java/src/json/ext/Parser.java +0 -2645
  58. data/java/src/json/ext/Parser.rl +0 -969
  59. data/java/src/json/ext/ParserService.java +0 -35
  60. data/java/src/json/ext/RuntimeInfo.java +0 -121
  61. data/java/src/json/ext/StringDecoder.java +0 -167
  62. data/java/src/json/ext/StringEncoder.java +0 -106
  63. data/java/src/json/ext/Utils.java +0 -89
  64. data/json-java.gemspec +0 -23
  65. data/json_pure.gemspec +0 -40
  66. data/lib/json/ext/.keep +0 -0
  67. data/tests/fixtures/fail1.json +0 -1
  68. data/tests/fixtures/fail10.json +0 -1
  69. data/tests/fixtures/fail11.json +0 -1
  70. data/tests/fixtures/fail12.json +0 -1
  71. data/tests/fixtures/fail13.json +0 -1
  72. data/tests/fixtures/fail14.json +0 -1
  73. data/tests/fixtures/fail18.json +0 -1
  74. data/tests/fixtures/fail19.json +0 -1
  75. data/tests/fixtures/fail2.json +0 -1
  76. data/tests/fixtures/fail20.json +0 -1
  77. data/tests/fixtures/fail21.json +0 -1
  78. data/tests/fixtures/fail22.json +0 -1
  79. data/tests/fixtures/fail23.json +0 -1
  80. data/tests/fixtures/fail24.json +0 -1
  81. data/tests/fixtures/fail25.json +0 -1
  82. data/tests/fixtures/fail27.json +0 -2
  83. data/tests/fixtures/fail28.json +0 -2
  84. data/tests/fixtures/fail3.json +0 -1
  85. data/tests/fixtures/fail4.json +0 -1
  86. data/tests/fixtures/fail5.json +0 -1
  87. data/tests/fixtures/fail6.json +0 -1
  88. data/tests/fixtures/fail7.json +0 -1
  89. data/tests/fixtures/fail8.json +0 -1
  90. data/tests/fixtures/fail9.json +0 -1
  91. data/tests/fixtures/pass1.json +0 -56
  92. data/tests/fixtures/pass15.json +0 -1
  93. data/tests/fixtures/pass16.json +0 -1
  94. data/tests/fixtures/pass17.json +0 -1
  95. data/tests/fixtures/pass2.json +0 -1
  96. data/tests/fixtures/pass26.json +0 -1
  97. data/tests/fixtures/pass3.json +0 -6
  98. data/tests/setup_variant.rb +0 -11
  99. data/tests/test_json.rb +0 -553
  100. data/tests/test_json_addition.rb +0 -196
  101. data/tests/test_json_encoding.rb +0 -65
  102. data/tests/test_json_fixtures.rb +0 -35
  103. data/tests/test_json_generate.rb +0 -337
  104. data/tests/test_json_generic_object.rb +0 -75
  105. data/tests/test_json_string_matching.rb +0 -39
  106. data/tests/test_json_unicode.rb +0 -72
  107. data/tools/fuzz.rb +0 -139
  108. data/tools/server.rb +0 -62
@@ -1,232 +0,0 @@
1
- /*
2
- * This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
3
- *
4
- * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
5
- * for details.
6
- */
7
- package json.ext;
8
-
9
- import java.lang.ref.WeakReference;
10
- import org.jruby.Ruby;
11
- import org.jruby.RubyArray;
12
- import org.jruby.RubyBoolean;
13
- import org.jruby.RubyFixnum;
14
- import org.jruby.RubyFloat;
15
- import org.jruby.RubyHash;
16
- import org.jruby.RubyInteger;
17
- import org.jruby.RubyModule;
18
- import org.jruby.RubyNumeric;
19
- import org.jruby.RubyString;
20
- import org.jruby.anno.JRubyMethod;
21
- import org.jruby.runtime.ThreadContext;
22
- import org.jruby.runtime.builtin.IRubyObject;
23
- import org.jruby.util.ByteList;
24
-
25
- /**
26
- * A class that populates the
27
- * <code>Json::Ext::Generator::GeneratorMethods</code> module.
28
- *
29
- * @author mernen
30
- */
31
- class GeneratorMethods {
32
- /**
33
- * Populates the given module with all modules and their methods
34
- * @param info
35
- * @param generatorMethodsModule The module to populate
36
- * (normally <code>JSON::Generator::GeneratorMethods</code>)
37
- */
38
- static void populate(RuntimeInfo info, RubyModule module) {
39
- defineMethods(module, "Array", RbArray.class);
40
- defineMethods(module, "FalseClass", RbFalse.class);
41
- defineMethods(module, "Float", RbFloat.class);
42
- defineMethods(module, "Hash", RbHash.class);
43
- defineMethods(module, "Integer", RbInteger.class);
44
- defineMethods(module, "NilClass", RbNil.class);
45
- defineMethods(module, "Object", RbObject.class);
46
- defineMethods(module, "String", RbString.class);
47
- defineMethods(module, "TrueClass", RbTrue.class);
48
-
49
- info.stringExtendModule = new WeakReference<RubyModule>(module.defineModuleUnder("String")
50
- .defineModuleUnder("Extend"));
51
- info.stringExtendModule.get().defineAnnotatedMethods(StringExtend.class);
52
- }
53
-
54
- /**
55
- * Convenience method for defining methods on a submodule.
56
- * @param parentModule
57
- * @param submoduleName
58
- * @param klass
59
- */
60
- private static void defineMethods(RubyModule parentModule,
61
- String submoduleName, Class klass) {
62
- RubyModule submodule = parentModule.defineModuleUnder(submoduleName);
63
- submodule.defineAnnotatedMethods(klass);
64
- }
65
-
66
-
67
- public static class RbHash {
68
- @JRubyMethod(rest=true)
69
- public static IRubyObject to_json(ThreadContext context,
70
- IRubyObject vSelf, IRubyObject[] args) {
71
- return Generator.generateJson(context, (RubyHash)vSelf,
72
- Generator.HASH_HANDLER, args);
73
- }
74
- }
75
-
76
- public static class RbArray {
77
- @JRubyMethod(rest=true)
78
- public static IRubyObject to_json(ThreadContext context,
79
- IRubyObject vSelf, IRubyObject[] args) {
80
- return Generator.generateJson(context, (RubyArray)vSelf,
81
- Generator.ARRAY_HANDLER, args);
82
- }
83
- }
84
-
85
- public static class RbInteger {
86
- @JRubyMethod(rest=true)
87
- public static IRubyObject to_json(ThreadContext context,
88
- IRubyObject vSelf, IRubyObject[] args) {
89
- return Generator.generateJson(context, vSelf, args);
90
- }
91
- }
92
-
93
- public static class RbFloat {
94
- @JRubyMethod(rest=true)
95
- public static IRubyObject to_json(ThreadContext context,
96
- IRubyObject vSelf, IRubyObject[] args) {
97
- return Generator.generateJson(context, (RubyFloat)vSelf,
98
- Generator.FLOAT_HANDLER, args);
99
- }
100
- }
101
-
102
- public static class RbString {
103
- @JRubyMethod(rest=true)
104
- public static IRubyObject to_json(ThreadContext context,
105
- IRubyObject vSelf, IRubyObject[] args) {
106
- return Generator.generateJson(context, (RubyString)vSelf,
107
- Generator.STRING_HANDLER, args);
108
- }
109
-
110
- /**
111
- * <code>{@link RubyString String}#to_json_raw(*)</code>
112
- *
113
- * <p>This method creates a JSON text from the result of a call to
114
- * {@link #to_json_raw_object} of this String.
115
- */
116
- @JRubyMethod(rest=true)
117
- public static IRubyObject to_json_raw(ThreadContext context,
118
- IRubyObject vSelf, IRubyObject[] args) {
119
- RubyHash obj = toJsonRawObject(context, Utils.ensureString(vSelf));
120
- return Generator.generateJson(context, obj,
121
- Generator.HASH_HANDLER, args);
122
- }
123
-
124
- /**
125
- * <code>{@link RubyString String}#to_json_raw_object(*)</code>
126
- *
127
- * <p>This method creates a raw object Hash, that can be nested into
128
- * other data structures and will be unparsed as a raw string. This
129
- * method should be used if you want to convert raw strings to JSON
130
- * instead of UTF-8 strings, e.g. binary data.
131
- */
132
- @JRubyMethod(rest=true)
133
- public static IRubyObject to_json_raw_object(ThreadContext context,
134
- IRubyObject vSelf, IRubyObject[] args) {
135
- return toJsonRawObject(context, Utils.ensureString(vSelf));
136
- }
137
-
138
- private static RubyHash toJsonRawObject(ThreadContext context,
139
- RubyString self) {
140
- Ruby runtime = context.getRuntime();
141
- RubyHash result = RubyHash.newHash(runtime);
142
-
143
- IRubyObject createId = RuntimeInfo.forRuntime(runtime)
144
- .jsonModule.get().callMethod(context, "create_id");
145
- result.op_aset(context, createId, self.getMetaClass().to_s());
146
-
147
- ByteList bl = self.getByteList();
148
- byte[] uBytes = bl.unsafeBytes();
149
- RubyArray array = runtime.newArray(bl.length());
150
- for (int i = bl.begin(), t = bl.begin() + bl.length(); i < t; i++) {
151
- array.store(i, runtime.newFixnum(uBytes[i] & 0xff));
152
- }
153
-
154
- result.op_aset(context, runtime.newString("raw"), array);
155
- return result;
156
- }
157
-
158
- @JRubyMethod(required=1, module=true)
159
- public static IRubyObject included(ThreadContext context,
160
- IRubyObject vSelf, IRubyObject module) {
161
- RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
162
- return module.callMethod(context, "extend", info.stringExtendModule.get());
163
- }
164
- }
165
-
166
- public static class StringExtend {
167
- /**
168
- * <code>{@link RubyString String}#json_create(o)</code>
169
- *
170
- * <p>Raw Strings are JSON Objects (the raw bytes are stored in an
171
- * array for the key "raw"). The Ruby String can be created by this
172
- * module method.
173
- */
174
- @JRubyMethod(required=1)
175
- public static IRubyObject json_create(ThreadContext context,
176
- IRubyObject vSelf, IRubyObject vHash) {
177
- Ruby runtime = context.getRuntime();
178
- RubyHash o = vHash.convertToHash();
179
- IRubyObject rawData = o.fastARef(runtime.newString("raw"));
180
- if (rawData == null) {
181
- throw runtime.newArgumentError("\"raw\" value not defined "
182
- + "for encoded String");
183
- }
184
- RubyArray ary = Utils.ensureArray(rawData);
185
- byte[] bytes = new byte[ary.getLength()];
186
- for (int i = 0, t = ary.getLength(); i < t; i++) {
187
- IRubyObject element = ary.eltInternal(i);
188
- if (element instanceof RubyFixnum) {
189
- bytes[i] = (byte)RubyNumeric.fix2long(element);
190
- } else {
191
- throw runtime.newTypeError(element, runtime.getFixnum());
192
- }
193
- }
194
- return runtime.newString(new ByteList(bytes, false));
195
- }
196
- }
197
-
198
- public static class RbTrue {
199
- @JRubyMethod(rest=true)
200
- public static IRubyObject to_json(ThreadContext context,
201
- IRubyObject vSelf, IRubyObject[] args) {
202
- return Generator.generateJson(context, (RubyBoolean)vSelf,
203
- Generator.TRUE_HANDLER, args);
204
- }
205
- }
206
-
207
- public static class RbFalse {
208
- @JRubyMethod(rest=true)
209
- public static IRubyObject to_json(ThreadContext context,
210
- IRubyObject vSelf, IRubyObject[] args) {
211
- return Generator.generateJson(context, (RubyBoolean)vSelf,
212
- Generator.FALSE_HANDLER, args);
213
- }
214
- }
215
-
216
- public static class RbNil {
217
- @JRubyMethod(rest=true)
218
- public static IRubyObject to_json(ThreadContext context,
219
- IRubyObject vSelf, IRubyObject[] args) {
220
- return Generator.generateJson(context, vSelf,
221
- Generator.NIL_HANDLER, args);
222
- }
223
- }
224
-
225
- public static class RbObject {
226
- @JRubyMethod(rest=true)
227
- public static IRubyObject to_json(ThreadContext context,
228
- IRubyObject self, IRubyObject[] args) {
229
- return RbString.to_json(context, self.asString(), args);
230
- }
231
- }
232
- }
@@ -1,43 +0,0 @@
1
- /*
2
- * This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
3
- *
4
- * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
5
- * for details.
6
- */
7
- package json.ext;
8
-
9
- import java.io.IOException;
10
- import java.lang.ref.WeakReference;
11
-
12
- import org.jruby.Ruby;
13
- import org.jruby.RubyClass;
14
- import org.jruby.RubyModule;
15
- import org.jruby.runtime.load.BasicLibraryService;
16
-
17
- /**
18
- * The service invoked by JRuby's {@link org.jruby.runtime.load.LoadService LoadService}.
19
- * Defines the <code>JSON::Ext::Generator</code> module.
20
- * @author mernen
21
- */
22
- public class GeneratorService implements BasicLibraryService {
23
- public boolean basicLoad(Ruby runtime) throws IOException {
24
- runtime.getLoadService().require("json/common");
25
- RuntimeInfo info = RuntimeInfo.initRuntime(runtime);
26
-
27
- info.jsonModule = new WeakReference<RubyModule>(runtime.defineModule("JSON"));
28
- RubyModule jsonExtModule = info.jsonModule.get().defineModuleUnder("Ext");
29
- RubyModule generatorModule = jsonExtModule.defineModuleUnder("Generator");
30
-
31
- RubyClass stateClass =
32
- generatorModule.defineClassUnder("State", runtime.getObject(),
33
- GeneratorState.ALLOCATOR);
34
- stateClass.defineAnnotatedMethods(GeneratorState.class);
35
- info.generatorStateClass = new WeakReference<RubyClass>(stateClass);
36
-
37
- RubyModule generatorMethods =
38
- generatorModule.defineModuleUnder("GeneratorMethods");
39
- GeneratorMethods.populate(info, generatorMethods);
40
-
41
- return true;
42
- }
43
- }