summaryrefslogtreecommitdiff
path: root/lib/json
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-01-02 23:46:25 +0100
committerFlorian Frank <flori@ping.de>2011-01-02 23:46:25 +0100
commit19bf4b3ea8869e7f1391f8c9de2a5fd4e3ddbc0b (patch)
tree1bce6e88780fec52afadb60135e4a12f7f8b5456 /lib/json
parent3f97501c35f00dec5dbafad8389154c67b1e4542 (diff)
parent6dc725aee27ddf514593ffafc9a98e3b20e698d3 (diff)
downloadjson-19bf4b3ea8869e7f1391f8c9de2a5fd4e3ddbc0b.tar.gz
Merge branch 'string-matching'
Conflicts: .gitignore Rakefile tests/test_json_encoding.rb
Diffstat (limited to 'lib/json')
-rw-r--r--lib/json/pure/parser.rb22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb
index 82a21e8..6a0192c 100644
--- a/lib/json/pure/parser.rb
+++ b/lib/json/pure/parser.rb
@@ -113,13 +113,13 @@ module JSON
else
@max_nesting = 0
end
- @allow_nan = !!opts[:allow_nan]
- @symbolize_names = !!opts[:symbolize_names]
- ca = true
- ca = opts[:create_additions] if opts.key?(:create_additions)
- @create_id = ca ? JSON.create_id : nil
- @object_class = opts[:object_class] || Hash
- @array_class = opts[:array_class] || Array
+ @allow_nan = !!opts[:allow_nan]
+ @symbolize_names = !!opts[:symbolize_names]
+ @create_additions = opts.key?(:create_additions) ? !!opts[:create_additions] : true
+ @create_id = opts[:create_id] || JSON.create_id
+ @object_class = opts[:object_class] || Hash
+ @array_class = opts[:array_class] || Array
+ @json_match = opts[:match] # @match is an ivar in rbx's strscan
end
alias source string
@@ -189,6 +189,12 @@ module JSON
if string.respond_to?(:force_encoding)
string.force_encoding(::Encoding::UTF_8)
end
+ if @create_additions and @json_match
+ for (regexp, klass) in @json_match
+ klass.json_creatable? or next
+ string =~ regexp and return klass.json_create(string)
+ end
+ end
string
else
UNPARSED
@@ -295,7 +301,7 @@ module JSON
if delim
raise ParserError, "expected next name, value pair in object at '#{peek(20)}'!"
end
- if @create_id and klassname = result[@create_id]
+ if @create_additions and klassname = result[@create_id]
klass = JSON.deep_const_get klassname
break unless klass and klass.json_creatable?
result = klass.json_create(result)