oj 2.4.3 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of oj might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/ext/oj/dump.c +17 -0
- data/ext/oj/oj.c +66 -0
- data/ext/oj/oj.h +1 -0
- data/lib/oj/version.rb +1 -1
- data/test/test_writer.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a372edadce1968a9ad2d8f63e6a3ddb59f7452a9
|
4
|
+
data.tar.gz: 7fde017753c41e55117a5959d20ca5cb42bad830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4024b5e1a5e33530cf5a714c62495bb06fc88225ae169ec429ac409b7f552637ffdcdfcb6f7d806a7fc4bc24d459ab8585d8f149044d7efb1eca23fc8320734b
|
7
|
+
data.tar.gz: 880b75ee95588c1da932492cdf0ae086f63061dc3ced0c87fe544a068e3b3f32de7b4c91c9c3a94da19b26843b629fe6a1757e2a10ad89b12c433dc326a8e601
|
data/README.md
CHANGED
@@ -20,6 +20,10 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
|
|
20
20
|
|
21
21
|
[![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
|
22
22
|
|
23
|
+
### Current Release 2.5.0
|
24
|
+
|
25
|
+
- Added push_json() to the StringWriter and StreamWriter to allow raw JSON to be added to a JSON document being constructed.
|
26
|
+
|
23
27
|
### Current Release 2.4.3
|
24
28
|
|
25
29
|
- Made include pthread.h conditional for Windows.
|
data/ext/oj/dump.c
CHANGED
@@ -2122,6 +2122,23 @@ oj_str_writer_push_value(StrWriter sw, VALUE val, const char *key) {
|
|
2122
2122
|
dump_val(val, sw->depth, &sw->out);
|
2123
2123
|
}
|
2124
2124
|
|
2125
|
+
void
|
2126
|
+
oj_str_writer_push_json(StrWriter sw, const char *json, const char *key) {
|
2127
|
+
long size;
|
2128
|
+
|
2129
|
+
key_check(sw, key);
|
2130
|
+
size = sw->depth * sw->out.indent + 3;
|
2131
|
+
if (sw->out.end - sw->out.cur <= size) {
|
2132
|
+
grow(&sw->out, size);
|
2133
|
+
}
|
2134
|
+
maybe_comma(sw);
|
2135
|
+
if (0 != key) {
|
2136
|
+
dump_cstr(key, strlen(key), 0, 0, &sw->out);
|
2137
|
+
*sw->out.cur++ = ':';
|
2138
|
+
}
|
2139
|
+
dump_raw(json, strlen(json), &sw->out);
|
2140
|
+
}
|
2141
|
+
|
2125
2142
|
void
|
2126
2143
|
oj_str_writer_pop(StrWriter sw) {
|
2127
2144
|
long size;
|
data/ext/oj/oj.c
CHANGED
@@ -965,6 +965,36 @@ str_writer_push_value(int argc, VALUE *argv, VALUE self) {
|
|
965
965
|
return Qnil;
|
966
966
|
}
|
967
967
|
|
968
|
+
/* call-seq: push_json(value, key=nil)
|
969
|
+
*
|
970
|
+
* Pushes a string onto the JSON document. The String must be a valid JSON
|
971
|
+
* encoded string. No additional checking is done to verify the validity of the
|
972
|
+
* string.
|
973
|
+
* @param [String] value JSON document to add to the JSON document
|
974
|
+
* @param [String] key the key if adding to an object in the JSON document
|
975
|
+
*/
|
976
|
+
static VALUE
|
977
|
+
str_writer_push_json(int argc, VALUE *argv, VALUE self) {
|
978
|
+
rb_check_type(argv[0], T_STRING);
|
979
|
+
switch (argc) {
|
980
|
+
case 1:
|
981
|
+
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), 0);
|
982
|
+
break;
|
983
|
+
case 2:
|
984
|
+
if (Qnil == argv[1]) {
|
985
|
+
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), 0);
|
986
|
+
} else {
|
987
|
+
rb_check_type(argv[1], T_STRING);
|
988
|
+
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), StringValuePtr(argv[1]));
|
989
|
+
}
|
990
|
+
break;
|
991
|
+
default:
|
992
|
+
rb_raise(rb_eArgError, "Wrong number of argument to 'push_json'.");
|
993
|
+
break;
|
994
|
+
}
|
995
|
+
return Qnil;
|
996
|
+
}
|
997
|
+
|
968
998
|
/* call-seq: pop()
|
969
999
|
*
|
970
1000
|
* Pops up a level in the JSON document closing the array or object that is
|
@@ -1196,6 +1226,40 @@ stream_writer_push_value(int argc, VALUE *argv, VALUE self) {
|
|
1196
1226
|
return Qnil;
|
1197
1227
|
}
|
1198
1228
|
|
1229
|
+
/* call-seq: push_value(value, key=nil)
|
1230
|
+
*
|
1231
|
+
* Pushes a string onto the JSON document. The String must be a valid JSON
|
1232
|
+
* encoded string. No additional checking is done to verify the validity of the
|
1233
|
+
* string.
|
1234
|
+
* @param [Object] value value to add to the JSON document
|
1235
|
+
* @param [String] key the key if adding to an object in the JSON document
|
1236
|
+
*/
|
1237
|
+
static VALUE
|
1238
|
+
stream_writer_push_json(int argc, VALUE *argv, VALUE self) {
|
1239
|
+
StreamWriter sw = (StreamWriter)DATA_PTR(self);
|
1240
|
+
|
1241
|
+
rb_check_type(argv[0], T_STRING);
|
1242
|
+
stream_writer_reset_buf(sw);
|
1243
|
+
switch (argc) {
|
1244
|
+
case 1:
|
1245
|
+
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), 0);
|
1246
|
+
break;
|
1247
|
+
case 2:
|
1248
|
+
if (Qnil == argv[0]) {
|
1249
|
+
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), 0);
|
1250
|
+
} else {
|
1251
|
+
rb_check_type(argv[1], T_STRING);
|
1252
|
+
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), StringValuePtr(argv[1]));
|
1253
|
+
}
|
1254
|
+
break;
|
1255
|
+
default:
|
1256
|
+
rb_raise(rb_eArgError, "Wrong number of argument to 'push_json'.");
|
1257
|
+
break;
|
1258
|
+
}
|
1259
|
+
stream_writer_write(sw);
|
1260
|
+
return Qnil;
|
1261
|
+
}
|
1262
|
+
|
1199
1263
|
/* call-seq: pop()
|
1200
1264
|
*
|
1201
1265
|
* Pops up a level in the JSON document closing the array or object that is
|
@@ -1623,6 +1687,7 @@ void Init_oj() {
|
|
1623
1687
|
rb_define_method(oj_string_writer_class, "push_object", str_writer_push_object, -1);
|
1624
1688
|
rb_define_method(oj_string_writer_class, "push_array", str_writer_push_array, -1);
|
1625
1689
|
rb_define_method(oj_string_writer_class, "push_value", str_writer_push_value, -1);
|
1690
|
+
rb_define_method(oj_string_writer_class, "push_json", str_writer_push_json, -1);
|
1626
1691
|
rb_define_method(oj_string_writer_class, "pop", str_writer_pop, 0);
|
1627
1692
|
rb_define_method(oj_string_writer_class, "pop_all", str_writer_pop_all, 0);
|
1628
1693
|
rb_define_method(oj_string_writer_class, "reset", str_writer_reset, 0);
|
@@ -1633,6 +1698,7 @@ void Init_oj() {
|
|
1633
1698
|
rb_define_method(oj_stream_writer_class, "push_object", stream_writer_push_object, -1);
|
1634
1699
|
rb_define_method(oj_stream_writer_class, "push_array", stream_writer_push_array, -1);
|
1635
1700
|
rb_define_method(oj_stream_writer_class, "push_value", stream_writer_push_value, -1);
|
1701
|
+
rb_define_method(oj_stream_writer_class, "push_json", stream_writer_push_json, -1);
|
1636
1702
|
rb_define_method(oj_stream_writer_class, "pop", stream_writer_pop, 0);
|
1637
1703
|
rb_define_method(oj_stream_writer_class, "pop_all", stream_writer_pop_all, 0);
|
1638
1704
|
|
data/ext/oj/oj.h
CHANGED
@@ -214,6 +214,7 @@ extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts);
|
|
214
214
|
extern void oj_str_writer_push_object(StrWriter sw, const char *key);
|
215
215
|
extern void oj_str_writer_push_array(StrWriter sw, const char *key);
|
216
216
|
extern void oj_str_writer_push_value(StrWriter sw, VALUE val, const char *key);
|
217
|
+
extern void oj_str_writer_push_json(StrWriter sw, const char *json, const char *key);
|
217
218
|
extern void oj_str_writer_pop(StrWriter sw);
|
218
219
|
extern void oj_str_writer_pop_all(StrWriter sw);
|
219
220
|
|
data/lib/oj/version.rb
CHANGED
data/test/test_writer.rb
CHANGED
@@ -76,6 +76,19 @@ class OjWriter < ::Test::Unit::TestCase
|
|
76
76
|
assert_equal('[7,7.3,true,null,"a string",{"a":65},[1,2]]', w.to_s)
|
77
77
|
end
|
78
78
|
|
79
|
+
def test_string_writer_json
|
80
|
+
w = Oj::StringWriter.new(:indent => 0)
|
81
|
+
w.push_array()
|
82
|
+
w.push_json('7')
|
83
|
+
w.push_json('true')
|
84
|
+
w.push_json(%|"a string"|)
|
85
|
+
w.push_object()
|
86
|
+
w.push_json('{"a":65}', 'x')
|
87
|
+
w.pop()
|
88
|
+
w.pop()
|
89
|
+
assert_equal('[7,true,"a string",{"x":{"a":65}}]', w.to_s)
|
90
|
+
end
|
91
|
+
|
79
92
|
def test_string_writer_pop_excess
|
80
93
|
w = Oj::StringWriter.new(:indent => 0)
|
81
94
|
begin
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'The fastest JSON parser and object serializer. '
|
14
14
|
email: peter@ohler.com
|