json 2.2.0 → 2.6.2

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