oj 3.16.0 → 3.16.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: affe42de16d26dfe301f38df7c0bc8ceee39ab25e5a6bd14bd7af6671cc3b422
4
- data.tar.gz: ee1d7227f864b197aca62cb767f9202798b6d3d13cf0b5f89eae3f3a36450dbb
3
+ metadata.gz: ce6ddad603b9b5d9629791f6bc35dffa1d31b99a6fe4692c1683140122186266
4
+ data.tar.gz: e15140778fc3f002dfa8b88d2620c5b24011f62b26c283d3b4844a121ff3f312
5
5
  SHA512:
6
- metadata.gz: 8dbf6a0b5fef2b179dba864b595113f73ac27a952307559422bf1feda19fcc008a5e43a142d1bb3eb0cc4125ff18f35730208c7f82b11089ff90690e7b1f17d0
7
- data.tar.gz: be09c04fa551288e2708c9151d0c966a09c3768ba15442cc54b8b4dd5850e2228b45608c06c8251c4e2ca32333353713f9c1feff81e4d34a48d1c6bf725014f6
6
+ metadata.gz: bbfca46d215dead1cd4941d77421163216d7bc87629619ea492fa9df2b9cf07fddb786fe1579a9916f30efe0a55ded53af0790f797cd1cd0e2205ef512ba5cc4
7
+ data.tar.gz: 22df787f55d70ec3766bd670e820fe54f1acaa8720534aaf50331b869542f252868a7875858c980fdfc29664c616d3f2cf8f8e5cde30d6ee5455e0728181035a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.16.2 - 2023-12-06
4
+
5
+ - Fixed documentation formatting.
6
+
7
+ - Added option to the "usual" parser to raise an error on an empty input string.
8
+
9
+ ## 3.16.1 - 2023-09-01
10
+
11
+ - Fixed exception type on number parsing. (thank you @jasonpenny)
12
+
3
13
  ## 3.16.0 - 2023-08-16
4
14
 
5
15
  - Added the `float_format` option.
data/ext/oj/cache.c CHANGED
@@ -260,7 +260,8 @@ void cache_set_expunge_rate(Cache c, int rate) {
260
260
  c->xrate = (uint8_t)rate;
261
261
  }
262
262
 
263
- void cache_free(Cache c) {
263
+ void cache_free(void *data) {
264
+ Cache c = (Cache)data;
264
265
  uint64_t i;
265
266
 
266
267
  for (i = 0; i < c->size; i++) {
@@ -276,7 +277,8 @@ void cache_free(Cache c) {
276
277
  OJ_FREE(c);
277
278
  }
278
279
 
279
- void cache_mark(Cache c) {
280
+ void cache_mark(void *data) {
281
+ Cache c = (Cache)data;
280
282
  uint64_t i;
281
283
 
282
284
  #if !HAVE_PTHREAD_MUTEX_INIT
data/ext/oj/cache.h CHANGED
@@ -10,10 +10,11 @@
10
10
  #define CACHE_MAX_KEY 35
11
11
 
12
12
  struct _cache;
13
+ typedef struct _cache *Cache;
13
14
 
14
15
  extern struct _cache *cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool mark, bool locking);
15
- extern void cache_free(struct _cache *c);
16
- extern void cache_mark(struct _cache *c);
16
+ extern void cache_free(void *data);
17
+ extern void cache_mark(void *data);
17
18
  extern void cache_set_form(struct _cache *c, VALUE (*form)(const char *str, size_t len));
18
19
  extern VALUE cache_intern(struct _cache *c, const char *key, size_t len);
19
20
  extern void cache_set_expunge_rate(struct _cache *c, int rate);
data/ext/oj/dump.c CHANGED
@@ -727,8 +727,11 @@ static void debug_raise(const char *orig, size_t cnt, int line) {
727
727
 
728
728
  void oj_dump_raw_json(VALUE obj, int depth, Out out) {
729
729
  if (oj_string_writer_class == rb_obj_class(obj)) {
730
- StrWriter sw = (StrWriter)DATA_PTR(obj);
731
- size_t len = sw->out.cur - sw->out.buf;
730
+ StrWriter sw;
731
+ size_t len;
732
+
733
+ sw = oj_str_writer_unwrap(obj);
734
+ len = sw->out.cur - sw->out.buf;
732
735
 
733
736
  if (0 < len) {
734
737
  len--;
data/ext/oj/fast.c CHANGED
@@ -780,11 +780,10 @@ static VALUE parse_json(VALUE clas, char *json, bool given) {
780
780
  }
781
781
  }
782
782
  #endif
783
- doc->json = json;
784
- self = TypedData_Wrap_Struct(clas, &oj_doc_type, doc);
785
- doc->self = self;
786
- DATA_PTR(doc->self) = doc;
787
- result = rb_protect(protect_open_proc, (VALUE)&pi, &ex);
783
+ doc->json = json;
784
+ self = TypedData_Wrap_Struct(clas, &oj_doc_type, doc);
785
+ doc->self = self;
786
+ result = rb_protect(protect_open_proc, (VALUE)&pi, &ex);
788
787
  if (given || 0 != ex) {
789
788
  DATA_PTR(doc->self) = NULL;
790
789
  // TBD is this needed?
@@ -1609,7 +1608,9 @@ static VALUE doc_dump(int argc, VALUE *argv, VALUE self) {
1609
1608
  * Oj::Doc.open('[1,2,3]') { |doc| doc.size() } #=> 4
1610
1609
  */
1611
1610
  static VALUE doc_size(VALUE self) {
1612
- return ULONG2NUM(((Doc)DATA_PTR(self))->size);
1611
+ Doc d;
1612
+ TypedData_Get_Struct(self, struct _doc, &oj_doc_type, d);
1613
+ return ULONG2NUM(d->size);
1613
1614
  }
1614
1615
 
1615
1616
  /* @overload close() => nil
data/ext/oj/intern.c CHANGED
@@ -85,20 +85,31 @@ static VALUE form_attr(const char *str, size_t len) {
85
85
  return (VALUE)rb_intern3(buf, len + 1, oj_utf8_encoding);
86
86
  }
87
87
 
88
+ static const rb_data_type_t oj_cache_type = {
89
+ "Oj/cache",
90
+ {
91
+ cache_mark,
92
+ cache_free,
93
+ NULL,
94
+ },
95
+ 0,
96
+ 0,
97
+ };
98
+
88
99
  void oj_hash_init(void) {
89
100
  VALUE cache_class = rb_define_class_under(Oj, "Cache", rb_cObject);
90
101
  rb_undef_alloc_func(cache_class);
91
102
 
92
103
  struct _cache *str_cache = cache_create(0, form_str, true, true);
93
- str_cache_obj = Data_Wrap_Struct(cache_class, cache_mark, cache_free, str_cache);
104
+ str_cache_obj = TypedData_Wrap_Struct(cache_class, &oj_cache_type, str_cache);
94
105
  rb_gc_register_address(&str_cache_obj);
95
106
 
96
107
  struct _cache *sym_cache = cache_create(0, form_sym, true, true);
97
- sym_cache_obj = Data_Wrap_Struct(cache_class, cache_mark, cache_free, sym_cache);
108
+ sym_cache_obj = TypedData_Wrap_Struct(cache_class, &oj_cache_type, sym_cache);
98
109
  rb_gc_register_address(&sym_cache_obj);
99
110
 
100
111
  struct _cache *attr_cache = cache_create(0, form_attr, false, true);
101
- attr_cache_obj = Data_Wrap_Struct(cache_class, cache_mark, cache_free, attr_cache);
112
+ attr_cache_obj = TypedData_Wrap_Struct(cache_class, &oj_cache_type, attr_cache);
102
113
  rb_gc_register_address(&attr_cache_obj);
103
114
 
104
115
  memset(class_hash.slots, 0, sizeof(class_hash.slots));
@@ -118,17 +129,23 @@ oj_str_intern(const char *key, size_t len) {
118
129
  #if HAVE_RB_ENC_INTERNED_STR && 0
119
130
  return rb_enc_interned_str(key, len, rb_utf8_encoding());
120
131
  #else
121
- return cache_intern(DATA_PTR(str_cache_obj), key, len);
132
+ Cache c;
133
+ TypedData_Get_Struct(str_cache_obj, struct _cache, &oj_cache_type, c);
134
+ return cache_intern(c, key, len);
122
135
  #endif
123
136
  }
124
137
 
125
138
  VALUE
126
139
  oj_sym_intern(const char *key, size_t len) {
127
- return cache_intern(DATA_PTR(sym_cache_obj), key, len);
140
+ Cache c;
141
+ TypedData_Get_Struct(sym_cache_obj, struct _cache, &oj_cache_type, c);
142
+ return cache_intern(c, key, len);
128
143
  }
129
144
 
130
145
  ID oj_attr_intern(const char *key, size_t len) {
131
- return cache_intern(DATA_PTR(attr_cache_obj), key, len);
146
+ Cache c;
147
+ TypedData_Get_Struct(attr_cache_obj, struct _cache, &oj_cache_type, c);
148
+ return cache_intern(c, key, len);
132
149
  }
133
150
 
134
151
  static uint64_t hash_calc(const uint8_t *key, size_t len) {
data/ext/oj/mimic_json.c CHANGED
@@ -425,7 +425,7 @@ static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) {
425
425
  * - *:object_nl* [_String_] String placed after a JSON object
426
426
  * - *:array_nl* [_String_] String placed after a JSON array
427
427
  * - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters in the output.
428
- * Note JSON.generate does support this even if it is not documented.
428
+ * Note JSON.generate does support this even if it is not documented.
429
429
  *
430
430
  * Returns [_String_] generated JSON.
431
431
  */
@@ -605,9 +605,9 @@ static VALUE mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
605
605
  * - *source* [_String_|IO] source to parse
606
606
  * - *opts* [_Hash_] options
607
607
  * - *:symbolize* [Boolean] _names flag indicating JSON object keys should be Symbols instead of
608
- * Strings
608
+ * Strings
609
609
  * - *:create_additions* [Boolean] flag indicating a key matching +create_id+ in a JSON object
610
- * should trigger the creation of Ruby Object
610
+ * should trigger the creation of Ruby Object
611
611
  *
612
612
  * Returns [Object]
613
613
  * @see create_id=
data/ext/oj/object.c CHANGED
@@ -83,8 +83,9 @@ static int parse_num(const char *str, const char *end, int cnt) {
83
83
 
84
84
  VALUE
85
85
  oj_parse_xml_time(const char *str, int len) {
86
- VALUE args[8];
87
- const char *end = str + len;
86
+ VALUE args[7];
87
+ const char *end = str + len;
88
+ const char *orig = str;
88
89
  int n;
89
90
 
90
91
  // year
@@ -144,7 +145,9 @@ oj_parse_xml_time(const char *str, int len) {
144
145
  char c = *str++;
145
146
 
146
147
  if ('.' == c) {
147
- long long nsec = 0;
148
+ unsigned long long num = 0;
149
+ unsigned long long den = 1;
150
+ const unsigned long long last_den_limit = ULLONG_MAX / 10;
148
151
 
149
152
  for (; str < end; str++) {
150
153
  c = *str;
@@ -152,9 +155,14 @@ oj_parse_xml_time(const char *str, int len) {
152
155
  str++;
153
156
  break;
154
157
  }
155
- nsec = nsec * 10 + (c - '0');
158
+ if (den > last_den_limit) {
159
+ // bail to Time.parse if there are more fractional digits than a ULLONG rational can hold
160
+ return rb_funcall(rb_cTime, oj_parse_id, 1, rb_str_new(orig, len));
161
+ }
162
+ num = num * 10 + (c - '0');
163
+ den *= 10;
156
164
  }
157
- args[5] = rb_float_new((double)n + ((double)nsec + 0.5) / 1000000000.0);
165
+ args[5] = rb_funcall(INT2NUM(n), oj_plus_id, 1, rb_rational_new(ULL2NUM(num), ULL2NUM(den)));
158
166
  } else {
159
167
  args[5] = rb_ll2inum(n);
160
168
  }
data/ext/oj/oj.c CHANGED
@@ -33,7 +33,6 @@ ID oj_array_append_id;
33
33
  ID oj_array_end_id;
34
34
  ID oj_array_start_id;
35
35
  ID oj_as_json_id;
36
- ID oj_at_id;
37
36
  ID oj_begin_id;
38
37
  ID oj_bigdecimal_id;
39
38
  ID oj_end_id;
@@ -51,6 +50,7 @@ ID oj_json_create_id;
51
50
  ID oj_length_id;
52
51
  ID oj_new_id;
53
52
  ID oj_parse_id;
53
+ ID oj_plus_id;
54
54
  ID oj_pos_id;
55
55
  ID oj_raw_json_id;
56
56
  ID oj_read_id;
@@ -91,9 +91,7 @@ VALUE oj_array_class_sym;
91
91
  VALUE oj_create_additions_sym;
92
92
  VALUE oj_decimal_class_sym;
93
93
  VALUE oj_hash_class_sym;
94
- VALUE oj_in_sym;
95
94
  VALUE oj_indent_sym;
96
- VALUE oj_nanosecond_sym;
97
95
  VALUE oj_object_class_sym;
98
96
  VALUE oj_quirks_mode_sym;
99
97
  VALUE oj_safe_sym;
@@ -240,72 +238,82 @@ struct _options oj_default_options = {
240
238
  * call-seq: default_options()
241
239
  *
242
240
  * Returns the default load and dump options as a Hash. The options are
243
- * - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in an JSON
244
- *document, zero or nil is no newline between JSON elements, negative indicates no newline between
245
- *top level JSON elements in a stream, a String indicates the string should be used for indentation
246
- * - *:circular* [_Boolean_|_nil_] support circular references while dumping as well as shared
247
- *references
241
+ * - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element
242
+ * in an JSON document, zero or nil is no newline between JSON elements,
243
+ * negative indicates no newline between top level JSON elements in a stream,
244
+ * a String indicates the string should be used for indentation
245
+ * - *:circular* [_Boolean_|_nil_] support circular references while dumping as
246
+ * well as shared references
248
247
  * - *:auto_define* [_Boolean_|_nil_] automatically define classes if they do not exist
249
248
  * - *:symbol_keys* [_Boolean_|_nil_] use symbols instead of strings for hash keys
250
- * - *:escape_mode* [_:newline_|_:json_|_:slash_|_:xss_safe_|_:ascii_|_:unicode_xss_|_nil_] determines the
251
- *characters to escape
252
- * - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing (if dynamically modifying
253
- *classes or reloading classes then don't use this)
254
- * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump modes
255
- *to use for JSON
249
+ * - *:escape_mode* [_:newline_|_:json_|_:slash_|_:xss_safe_|_:ascii_|_:unicode_xss_|_nil_]
250
+ * determines the characters to escape
251
+ * - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing (if dynamically
252
+ * modifying classes or reloading classes then don't use this)
253
+ * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and
254
+ * dump modes to use for JSON
256
255
  * - *:time_format* [_:unix_|_:unix_zone_|_:xmlschema_|_:ruby_] time format when dumping
257
- * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a String
258
- * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_:fast_|_:ruby_] load decimals as BigDecimal instead
259
- *of as a Float. :auto pick the most precise for the number of digits. :float should be the same as
260
- *ruby. :fast may require rounding but is must faster.
261
- * - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as a Float when in
262
- *compat or rails mode.
263
- * - *:create_id* [_String_|_nil_] create id for json compatible object encoding, default is
264
- *'json_class'
265
- * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on
266
- *load.
267
- * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the
268
- *seconds portion of time
269
- * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0
270
- *indicates use Ruby
271
- * - *:float_format* [_String_] the C printf format string for printing floats. Default follows
272
- * the float_precision and will be changed if float_precision is changed. The string can be no more than 6 bytes.
256
+ * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or
257
+ * as a String
258
+ * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_:fast_|_:ruby_] load decimals
259
+ * as BigDecimal instead of as a Float. :auto pick the most precise for the number
260
+ * of digits. :float should be the same as ruby. :fast may require rounding but is
261
+ * must faster.
262
+ * - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as
263
+ * a Float when in compat or rails mode.
264
+ * - *:create_id* [_String_|_nil_] create id for json compatible object encoding,
265
+ * default is 'json_class'
266
+ * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using
267
+ * create_id on load.
268
+ * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when
269
+ * dumping the seconds portion of time
270
+ * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping
271
+ * floats, 0 indicates use Ruby
272
+ * - *:float_format* [_String_] the C printf format string for printing floats.
273
+ * Default follows the float_precision and will be changed if float_precision is
274
+ * changed. The string can be no more than 6 bytes.
273
275
  * - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false
274
276
  * - *:use_as_json* [_Boolean_|_nil_] call as_json() methods on dump, default is false
275
277
  * - *:use_raw_json* [_Boolean_|_nil_] call raw_json() methods on dump, default is false
276
- * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an
277
- *Exception
278
+ * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and
279
+ * not raise an Exception
278
280
  * - *:empty_string* [_Boolean_|_nil_] if true an empty input will not raise an Exception
279
281
  * - *:allow_gc* [_Boolean_|_nil_] allow or prohibit GC during parsing, default is true (allow)
280
- * - *:quirks_mode* [_true,_|_false_|_nil_] Allow single JSON values instead of documents, default
281
- *is true (allow)
282
- * - *:allow_invalid_unicode* [_true,_|_false_|_nil_] Allow invalid unicode, default is false (don't
283
- *allow)
284
- * - *:allow_nan* [_true,_|_false_|_nil_] Allow Nan, Infinity, and -Infinity to be parsed, default
285
- *is true (allow)
286
- * - *:indent_str* [_String_|_nil_] String to use for indentation, overriding the indent option is
287
- *not nil
288
- * - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields
289
- * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object fields
282
+ * - *:quirks_mode* [_true,_|_false_|_nil_] Allow single JSON values instead of
283
+ * documents, default is true (allow)
284
+ * - *:allow_invalid_unicode* [_true,_|_false_|_nil_] Allow invalid unicode,
285
+ * default is false (don't allow)
286
+ * - *:allow_nan* [_true,_|_false_|_nil_] Allow Nan, Infinity, and -Infinity to
287
+ * be parsed, default is true (allow)
288
+ * - *:indent_str* [_String_|_nil_] String to use for indentation, overriding the
289
+ * indent option is not nil
290
+ * - *:space* [_String_|_nil_] String to use for the space after the colon in JSON
291
+ * object fields
292
+ * - *:space_before* [_String_|_nil_] String to use before the colon separator in
293
+ * JSON object fields
290
294
  * - *:object_nl* [_String_|_nil_] String to use after a JSON object field value
291
295
  * - *:array_nl* [_String_|_nil_] String to use after a JSON array value
292
- * - *:nan* [_:null_|_:huge_|_:word_|_:raise_|_:auto_] how to dump Infinity and NaN. :null places a
293
- *null, :huge places a huge number, :word places Infinity or NaN, :raise raises and exception, :auto
294
- *uses default for each mode.
295
- * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be
296
- *used
296
+ * - *:nan* [_:null_|_:huge_|_:word_|_:raise_|_:auto_] how to dump Infinity and
297
+ * NaN. :null places a null, :huge places a huge number, :word places Infinity
298
+ * or NaN, :raise raises and exception, :auto uses default for each mode.
299
+ * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load,
300
+ * :object_class can also be used
297
301
  * - *:array_class* [_Class_|_nil_] Class to use instead of Array on load
298
- * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted
299
- * - *:omit_null_byte* [_true_|_false_] if true null bytes in strings will be omitted when dumping
302
+ * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil
303
+ * values are omitted
304
+ * - *:omit_null_byte* [_true_|_false_] if true null bytes in strings will be
305
+ * omitted when dumping
300
306
  * - *:ignore* [_nil_|_Array_] either nil or an Array of classes to ignore when dumping
301
- * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when dumping in
302
- *object or custom mode.
307
+ * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are
308
+ * ignored when dumping in object or custom mode.
303
309
  * - *:cache_keys* [_Boolean_] if true then hash keys are cached if less than 35 bytes.
304
- * - *:cache_str* [_Fixnum_] maximum string value length to cache (strings less than this are cached)
310
+ * - *:cache_str* [_Fixnum_] maximum string value length to cache (strings less
311
+ * than this are cached)
305
312
  * - *:integer_range* [_Range_] Dump integers outside range as strings.
306
- * - *:trace* [_true,_|_false_] Trace all load and dump calls, default is false (trace is off)
307
- * - *:safe* [_true,_|_false_] Safe mimic breaks JSON mimic to be safer, default is false (safe is
308
- *off)
313
+ * - *:trace* [_true,_|_false_] Trace all load and dump calls, default is false
314
+ * (trace is off)
315
+ * - *:safe* [_true,_|_false_] Safe mimic breaks JSON mimic to be safer, default
316
+ * is false (safe is off)
309
317
  *
310
318
  * Return [_Hash_] all current option settings.
311
319
  */
@@ -490,70 +498,67 @@ static VALUE get_def_opts(VALUE self) {
490
498
  *
491
499
  * Sets the default options for load and dump.
492
500
  * - *opts* [_Hash_] options to change
493
- * - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in a JSON
494
- *document or the String to use for indentation.
501
+ * - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element
502
+ * in a JSON document or the String to use for indentation.
495
503
  * - :circular [_Boolean_|_nil_] support circular references while dumping.
496
504
  * - *:auto_define* [_Boolean_|_nil_] automatically define classes if they do not exist.
497
505
  * - *:symbol_keys* [_Boolean_|_nil_] convert hash keys to symbols.
498
506
  * - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing.
499
- * - *:escape* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_] mode encodes all
500
- *high-bit characters as escaped sequences if :ascii, :json is standand UTF-8 JSON encoding,
501
- *:newline is the same as :json but newlines are not escaped, :unicode_xss allows unicode but
502
- *escapes &, <, and >, and any \u20xx characters along with some others, and :xss_safe escapes &, <,
503
- *and >, and some others.
504
- * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a
505
- *String.
506
- * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_nil_] load decimals as BigDecimal instead
507
- *of as a Float. :auto pick the most precise for the number of digits.
508
- * - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as a Float in
509
- *compat mode.
510
- * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump mode
511
- *to use for JSON :strict raises an exception when a non-supported Object is encountered. :compat
512
- *attempts to extract variable values from an Object using to_json() or to_hash() then it walks the
513
- *Object's variables if neither is found. The :object mode ignores to_hash() and to_json() methods
514
- *and encodes variables using code internal to the Oj gem. The :null mode ignores non-supported
515
- *Objects and replaces them with a null. The :custom mode honors all dump options. The :rails more
516
- *mimics rails and Active behavior.
517
- * - *:time_format* [_:unix_|_:xmlschema_|_:ruby_] time format when dumping in :compat mode :unix
518
- *decimal number denoting the number of seconds since 1/1/1970, :unix_zone decimal number denoting
519
- *the number of seconds since 1/1/1970 plus the utc_offset in the exponent, :xmlschema date-time
520
- *format taken from XML Schema as a String, :ruby Time.to_s formatted String.
507
+ * - *:escape* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_]
508
+ * mode encodes all high-bit characters as escaped sequences if :ascii, :json
509
+ * is standand UTF-8 JSON encoding, :newline is the same as :json but newlines
510
+ * are not escaped, :unicode_xss allows unicode but escapes &, <, and >, and
511
+ * any \u20xx characters along with some others, and :xss_safe escapes &, <,
512
+ * and >, and some others.
513
+ * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal
514
+ * number or as a String.
515
+ * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_nil_] load decimals as
516
+ * BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.
517
+ * - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead
518
+ * of as a Float in compat mode.
519
+ * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load
520
+ * and dump mode to use for JSON :strict raises an exception when a non-supported
521
+ * Object is encountered. :compat attempts to extract variable values from an
522
+ * Object using to_json() or to_hash() then it walks the Object's variables if
523
+ * neither is found. The :object mode ignores to_hash() and to_json() methods
524
+ * and encodes variables using code internal to the Oj gem. The :null mode
525
+ * ignores non-supported Objects and replaces them with a null. The :custom
526
+ * mode honors all dump options. The :rails more mimics rails and Active behavior.
527
+ * - *:time_format* [_:unix_|_:xmlschema_|_:ruby_] time format when dumping in :compat
528
+ * mode :unix decimal number denoting the number of seconds since 1/1/1970,
529
+ * :unix_zone decimal number denoting the number of seconds since 1/1/1970
530
+ * plus the utc_offset in the exponent, :xmlschema date-time format taken
531
+ * from XML Schema as a String, :ruby Time.to_s formatted String.
521
532
  * - *:create_id* [_String_|_nil_] create id for json compatible object encoding
522
- * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on
523
- *load.
524
- * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the
525
- *seconds portion of time.
526
- * - *:float_format* [_String_] the C printf format string for printing floats. Default follows
527
- * the float_precision and will be changed if float_precision is changed. The string can be no more than 6 bytes.
528
- * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0
529
- *indicates use Ruby.
533
+ * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on load.
534
+ * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal
535
+ * when dumping the seconds portion of time.
536
+ * - *:float_format* [_String_] the C printf format string for printing floats.
537
+ * Default follows the float_precision and will be changed if float_precision
538
+ * is changed. The string can be no more than 6 bytes.
539
+ * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0 indicates use Ruby.
530
540
  * - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false.
531
541
  * - *:use_as_json* [_Boolean_|_nil_] call as_json() methods on dump, default is false.
532
542
  * - *:use_to_hash* [_Boolean_|_nil_] call to_hash() methods on dump, default is false.
533
543
  * - *:use_raw_json* [_Boolean_|_nil_] call raw_json() methods on dump, default is false.
534
- * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an
535
- *Exception.
544
+ * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an Exception.
536
545
  * - *:allow_gc* [_Boolean_|_nil_] allow or prohibit GC during parsing, default is true (allow).
537
- * - *:quirks_mode* [_Boolean_|_nil_] allow single JSON values instead of documents, default is
538
- *true (allow).
539
- * - *:allow_invalid_unicode* [_Boolean_|_nil_] allow invalid unicode, default is false (don't
540
- *allow).
546
+ * - *:quirks_mode* [_Boolean_|_nil_] allow single JSON values instead of documents, default is true (allow).
547
+ * - *:allow_invalid_unicode* [_Boolean_|_nil_] allow invalid unicode, default is false (don't allow).
541
548
  * - *:allow_nan* [_Boolean_|_nil_] allow Nan, Infinity, and -Infinity, default is true (allow).
542
549
  * - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields.
543
- * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object
544
- *fields.
550
+ * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object fields.
545
551
  * - *:object_nl* [_String_|_nil_] String to use after a JSON object field value.
546
552
  * - *:array_nl* [_String_|_nil_] String to use after a JSON array value
547
- * - *:nan* [_:null_|_:huge_|_:word_|_:raise_] how to dump Infinity and NaN in null, strict, and
548
- *compat mode. :null places a null, :huge places a huge number, :word places Infinity or NaN, :raise
549
- *raises and exception, :auto uses default for each mode.
550
- * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be
551
- *used.
553
+ * - *:nan* [_:null_|_:huge_|_:word_|_:raise_] how to dump Infinity and NaN in null,
554
+ * strict, and compat mode. :null places a null, :huge places a huge number, :word
555
+ * places Infinity or NaN, :raise raises and exception, :auto uses default for each mode.
556
+ * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be used.
552
557
  * - *:array_class* [_Class_|_nil_] Class to use instead of Array on load.
553
558
  * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted.
554
559
  * - *:ignore* [_nil_|Array] either nil or an Array of classes to ignore when dumping
555
- * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when
556
- *dumping in object or custom mode.
560
+ * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are
561
+ * ignored when dumping in object or custom mode.
557
562
  * - *:cache_keys* [_Boolean_] if true then hash keys are cached
558
563
  * - *:cache_str* [_Fixnum_] maximum string value length to cache (strings less than this are cached)
559
564
  * - *:integer_range* [_Range_] Dump integers outside range as strings.
@@ -1329,18 +1334,16 @@ static VALUE dump(int argc, VALUE *argv, VALUE self) {
1329
1334
  * will be called. The mode is set to :compat.
1330
1335
  * - *obj* [_Object_] Object to serialize as an JSON document String
1331
1336
  * - *options* [_Hash_]
1332
- * - *:max_nesting* [_Fixnum_|_boolean_] It true nesting is limited to 100. If a Fixnum nesting
1333
- * is set to the provided value. The option to detect circular references is available but is not
1334
- * compatible with the json gem., default is false or unlimited.
1335
- * - *:allow_nan* [_boolean_] If true non JSON compliant words such as Nan and Infinity will be
1336
- * used as appropriate, default is true.
1337
- * - *:quirks_mode* [_boolean_] Allow single JSON values instead of documents, default is true
1338
- * (allow).
1339
- * - *:indent* [_String_|_nil_] String to use for indentation, overriding the indent option if not
1340
- * nil.
1337
+ * - *:max_nesting* [_Fixnum_|_boolean_] It true nesting is limited to 100.
1338
+ * If a Fixnum nesting is set to the provided value. The option to detect
1339
+ * circular references is available but is not compatible with the json gem.,
1340
+ * default is false or unlimited.
1341
+ * - *:allow_nan* [_boolean_] If true non JSON compliant words such as Nan and
1342
+ * Infinity will be used as appropriate, default is true.
1343
+ * - *:quirks_mode* [_boolean_] Allow single JSON values instead of documents, default is true (allow).
1344
+ * - *:indent* [_String_|_nil_] String to use for indentation, overriding the indent option if not nil.
1341
1345
  * - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields.
1342
- * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object
1343
- * fields.
1346
+ * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object fields.
1344
1347
  * - *:object_nl* [_String_|_nil_] String to use after a JSON object field value.
1345
1348
  * - *:array_nl* [_String_|_nil_] String to use after a JSON array value.
1346
1349
  * - *:trace* [_Boolean_] If true trace is turned on.
@@ -1435,10 +1438,10 @@ static VALUE to_stream(int argc, VALUE *argv, VALUE self) {
1435
1438
  *
1436
1439
  * - *clas* [_Class__|_Module_] Class or Module to be made special
1437
1440
  * - *create_object* [_Object_] object to call the create method on
1438
- * - *create_method* [_Symbol_] method on the clas that will create a new instance of the clas when
1439
- * given all the member values in the order specified.
1440
- * - *members* [_Symbol__|_String_] methods used to get the member values from instances of the
1441
- * clas.
1441
+ * - *create_method* [_Symbol_] method on the clas that will create a new instance
1442
+ * of the clas when given all the member values in the order specified.
1443
+ * - *members* [_Symbol__|_String_] methods used to get the member values from
1444
+ * instances of the clas.
1442
1445
  */
1443
1446
  static VALUE register_odd(int argc, VALUE *argv, VALUE self) {
1444
1447
  if (3 > argc) {
@@ -1471,10 +1474,10 @@ static VALUE register_odd(int argc, VALUE *argv, VALUE self) {
1471
1474
  *
1472
1475
  * - *clas* [_Class_|_Module_] Class or Module to be made special
1473
1476
  * - *create_object* [_Object_] object to call the create method on
1474
- * - *create_method* [_Symbol_] method on the clas that will create a new instance of the clas when
1475
- *given all the member values in the order specified.
1476
- * - *dump_method* [_Symbol_|_String_] method to call on the object being serialized to generate the
1477
- *raw JSON.
1477
+ * - *create_method* [_Symbol_] method on the clas that will create a new instance
1478
+ * of the clas when given all the member values in the order specified.
1479
+ * - *dump_method* [_Symbol_|_String_] method to call on the object being
1480
+ * serialized to generate the raw JSON.
1478
1481
  */
1479
1482
  static VALUE register_odd_raw(int argc, VALUE *argv, VALUE self) {
1480
1483
  if (3 > argc) {
@@ -1700,8 +1703,8 @@ extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
1700
1703
  * - *:space_before* [_String_] String placed before a : delimiter
1701
1704
  * - *:object_nl* [_String_] String placed after a JSON object
1702
1705
  * - *:array_nl* [_String_] String placed after a JSON array
1703
- * - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters in the output.
1704
- * Note JSON.generate does support this even if it is not documented.
1706
+ * - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters
1707
+ * in the output. Note JSON.generate does support this even if it is not documented.
1705
1708
  *
1706
1709
  * Returns [_String_]generated JSON.
1707
1710
  */
@@ -1758,8 +1761,8 @@ static VALUE mem_report(VALUE self) {
1758
1761
  * global and options to methods allow additional behavior modifications. The
1759
1762
  * modes are:
1760
1763
  *
1761
- * - *:strict* mode will only allow the 7 basic JSON types to be serialized. Any other Object
1762
- * will raise an Exception.
1764
+ * - *:strict* mode will only allow the 7 basic JSON types to be serialized.
1765
+ * Any other Object will raise an Exception.
1763
1766
  *
1764
1767
  * - *:null* mode is similar to the :strict mode except any Object that is not
1765
1768
  * one of the JSON base types is replaced by a JSON null.
@@ -1843,7 +1846,6 @@ void Init_oj(void) {
1843
1846
  oj_array_end_id = rb_intern("array_end");
1844
1847
  oj_array_start_id = rb_intern("array_start");
1845
1848
  oj_as_json_id = rb_intern("as_json");
1846
- oj_at_id = rb_intern("at");
1847
1849
  oj_begin_id = rb_intern("begin");
1848
1850
  oj_bigdecimal_id = rb_intern("BigDecimal");
1849
1851
  oj_end_id = rb_intern("end");
@@ -1861,6 +1863,7 @@ void Init_oj(void) {
1861
1863
  oj_length_id = rb_intern("length");
1862
1864
  oj_new_id = rb_intern("new");
1863
1865
  oj_parse_id = rb_intern("parse");
1866
+ oj_plus_id = rb_intern("+");
1864
1867
  oj_pos_id = rb_intern("pos");
1865
1868
  oj_raw_json_id = rb_intern("raw_json");
1866
1869
  oj_read_id = rb_intern("read");
@@ -1993,14 +1996,10 @@ void Init_oj(void) {
1993
1996
  rb_gc_register_address(&oj_decimal_class_sym);
1994
1997
  oj_hash_class_sym = ID2SYM(rb_intern("hash_class"));
1995
1998
  rb_gc_register_address(&oj_hash_class_sym);
1996
- oj_in_sym = ID2SYM(rb_intern("in"));
1997
- rb_gc_register_address(&oj_in_sym);
1998
1999
  oj_indent_sym = ID2SYM(rb_intern("indent"));
1999
2000
  rb_gc_register_address(&oj_indent_sym);
2000
2001
  oj_max_nesting_sym = ID2SYM(rb_intern("max_nesting"));
2001
2002
  rb_gc_register_address(&oj_max_nesting_sym);
2002
- oj_nanosecond_sym = ID2SYM(rb_intern("nanosecond"));
2003
- rb_gc_register_address(&oj_nanosecond_sym);
2004
2003
  oj_object_class_sym = ID2SYM(rb_intern("object_class"));
2005
2004
  rb_gc_register_address(&oj_object_class_sym);
2006
2005
  oj_object_nl_sym = ID2SYM(rb_intern("object_nl"));