brianmario-yajl-ruby 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## 0.5.3 (Jun 7th, 2009)
3
+ ## 0.5.4 (June 16th, 2009)
4
+ * Yajl::Parser's :symbolize_keys option now defaults to false
5
+ * remove use of sprintf for a little speed improvement while parsing
6
+
7
+ ## 0.5.3 (June 7th, 2009)
4
8
  * The IO parameter for Yajl::Encode#encode is now optional, and accepts a block
5
9
  ** it will return the resulting JSON string if no IO is passed to stream to
6
10
  ** if a block is passed, it will call and pass it the resulting JSON string
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 5
4
- :patch: 3
4
+ :patch: 4
data/ext/yajl_ext.c CHANGED
@@ -166,9 +166,7 @@ static int yajl_found_number(void * ctx, const char * numberVal, unsigned int nu
166
166
  VALUE subString = rb_str_new(numberVal, numberLen);
167
167
  char * cSubString = RSTRING_PTR(subString);
168
168
 
169
- if (strstr(cSubString, ".") != NULL ||
170
- strstr(cSubString, "e") != NULL ||
171
- strstr(cSubString, "E") != NULL) {
169
+ if (strstr(cSubString, ".") != NULL || strstr(cSubString, "e") != NULL || strstr(cSubString, "E") != NULL) {
172
170
  yajl_set_static_value(ctx, rb_Float(subString));
173
171
  } else {
174
172
  yajl_set_static_value(ctx, rb_Integer(subString));
@@ -186,15 +184,13 @@ static int yajl_found_string(void * ctx, const unsigned char * stringVal, unsign
186
184
  static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsigned int stringLen) {
187
185
  struct yajl_parser_wrapper * wrapper;
188
186
  GetParser((VALUE)ctx, wrapper);
187
+ VALUE keyStr = rb_str_new((const char *)stringVal, stringLen);
189
188
 
190
189
  if (wrapper->symbolizeKeys) {
191
- char keyStr[stringLen];
192
- ID key;
193
- sprintf(keyStr, "%.*s", stringLen, stringVal);
194
- key = rb_intern(keyStr);
190
+ ID key = rb_intern(RSTRING_PTR(keyStr));
195
191
  yajl_set_static_value(ctx, ID2SYM(key));
196
192
  } else {
197
- yajl_set_static_value(ctx, rb_str_new((const char *)stringVal, stringLen));
193
+ yajl_set_static_value(ctx, keyStr);
198
194
  }
199
195
  yajl_check_and_fire_callback(ctx);
200
196
  return 1;
@@ -252,17 +248,19 @@ static int yajl_found_end_array(void * ctx) {
252
248
  /*
253
249
  * Document-method: new
254
250
  *
255
- * call-seq: new([:allow_comments => false, :check_utf8 => false])
251
+ * call-seq: new([:symbolize_keys => true, [:allow_comments => false[, :check_utf8 => false]]])
256
252
  *
257
- * :allow_comments will turn on/off the check for comments inside the JSON stream.
253
+ * :symbolize_keys will turn hash keys into Ruby symbols, defaults to false.
258
254
  *
259
- * :check_utf8 will validate UTF8 characters found in the JSON stream.
255
+ * :allow_comments will turn on/off the check for comments inside the JSON stream, defaults to true.
256
+ *
257
+ * :check_utf8 will validate UTF8 characters found in the JSON stream, defaults to true.
260
258
  */
261
259
  static VALUE rb_yajl_parser_new(int argc, VALUE * argv, VALUE klass) {
262
260
  struct yajl_parser_wrapper * wrapper;
263
261
  yajl_parser_config cfg;
264
262
  VALUE opts, obj;
265
- int allowComments = 1, checkUTF8 = 1, symbolizeKeys = 1;
263
+ int allowComments = 1, checkUTF8 = 1, symbolizeKeys = 0;
266
264
 
267
265
  // Scan off config vars
268
266
  if (rb_scan_args(argc, argv, "01", &opts) == 1) {
@@ -274,8 +272,8 @@ static VALUE rb_yajl_parser_new(int argc, VALUE * argv, VALUE klass) {
274
272
  if (rb_hash_aref(opts, ID2SYM(sym_check_utf8)) == Qfalse) {
275
273
  checkUTF8 = 0;
276
274
  }
277
- if (rb_hash_aref(opts, ID2SYM(sym_symbolize_keys)) == Qfalse) {
278
- symbolizeKeys = 0;
275
+ if (rb_hash_aref(opts, ID2SYM(sym_symbolize_keys)) == Qtrue) {
276
+ symbolizeKeys = 1;
279
277
  }
280
278
  }
281
279
  cfg = (yajl_parser_config){allowComments, checkUTF8};
@@ -295,12 +293,14 @@ static VALUE rb_yajl_parser_new(int argc, VALUE * argv, VALUE klass) {
295
293
  /*
296
294
  * Document-method: initialize
297
295
  *
298
- * call-seq: initialize([:allow_comments => false, :check_utf8 => false])
296
+ * call-seq: new([:symbolize_keys => true, [:allow_comments => false[, :check_utf8 => false]]])
299
297
  *
300
- * :allow_comments will turn on/off the check for comments inside the JSON stream.
298
+ * :symbolize_keys will turn hash keys into Ruby symbols, defaults to false.
301
299
  *
302
- * :check_utf8 will validate UTF8 characters found in the JSON stream.
303
- */
300
+ * :allow_comments will turn on/off the check for comments inside the JSON stream, defaults to true.
301
+ *
302
+ * :check_utf8 will validate UTF8 characters found in the JSON stream, defaults to true.
303
+ */
304
304
  static VALUE rb_yajl_parser_init(int argc, VALUE * argv, VALUE self) {
305
305
  return self;
306
306
  }
@@ -4,7 +4,7 @@ require 'stringio'
4
4
 
5
5
  describe "Chunked parser" do
6
6
  before(:all) do
7
- @final = [{:abc => 123}, {:def => 456}]
7
+ @final = [{"abc" => 123}, {"def" => 456}]
8
8
  end
9
9
 
10
10
  before(:each) do
@@ -6,7 +6,7 @@ describe "One-off JSON examples" do
6
6
  infinity = (1.0/0)
7
7
  silence_warnings do
8
8
  parser = Yajl::Parser.new
9
- parser.parse(StringIO.new('{"key": 23456789012E666}')).should == {:key => infinity}
9
+ parser.parse(StringIO.new('{"key": 23456789012E666}')).should == {"key" => infinity}
10
10
  end
11
11
  end
12
12
 
@@ -36,16 +36,16 @@ describe "One-off JSON examples" do
36
36
 
37
37
  it "should parse using it's class method, from an IO" do
38
38
  io = StringIO.new('{"key": 1234}')
39
- Yajl::Parser.parse(io).should == {:key => 1234}
39
+ Yajl::Parser.parse(io).should == {"key" => 1234}
40
40
  end
41
41
 
42
- it "should parse using it's class method, from an IO with string keys" do
42
+ it "should parse using it's class method, from an IO with symbolized keys" do
43
43
  parser = Yajl::Parser.new(:symbolize_keys => true)
44
44
  parser.parse('{"key": 1234}').should == {:key => 1234}
45
45
  end
46
46
 
47
47
  it "should parse using it's class method, from a string" do
48
- Yajl::Parser.parse('{"key": 1234}').should == {:key => 1234}
48
+ Yajl::Parser.parse('{"key": 1234}').should == {"key" => 1234}
49
49
  end
50
50
 
51
51
  it "should parse using it's class method, from a string with a block" do
@@ -53,6 +53,6 @@ describe "One-off JSON examples" do
53
53
  Yajl::Parser.parse('{"key": 1234}') do |obj|
54
54
  output = obj
55
55
  end
56
- output.should == {:key => 1234}
56
+ output.should == {"key" => 1234}
57
57
  end
58
58
  end
data/yajl-ruby.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{yajl-ruby}
5
- s.version = "0.5.3"
5
+ s.version = "0.5.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Brian Lopez", "Lloyd Hilaiel"]
9
- s.date = %q{2009-06-07}
9
+ s.date = %q{2009-06-16}
10
10
  s.email = %q{seniorlopez@gmail.com}
11
11
  s.extensions = ["ext/extconf.rb"]
12
12
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brianmario-yajl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-07 00:00:00 -07:00
13
+ date: 2009-06-16 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16