summaryrefslogtreecommitdiff
path: root/ext/json/lib/json/pure/parser.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-03 10:36:10 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-03 10:36:10 +0000
commitbe93ac50db6b8dc8f3eedd8c9779a8c82fd694e6 (patch)
tree1ceb2589d54322c44c40876c791bea4a973046f2 /ext/json/lib/json/pure/parser.rb
parent7e752551bbe122f57eb3536077804ddf7979244b (diff)
* ext/json/lib/json/pure.rb (module JSON): remove Iconv dependency.
* ext/json/lib/json/pure/generator.rb (utf8_to_json): process as binary and remove Iconv dependency. * ext/json/lib/json/pure/parser.rb (parse_string): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/lib/json/pure/parser.rb')
-rw-r--r--ext/json/lib/json/pure/parser.rb26
1 files changed, 18 insertions, 8 deletions
diff --git a/ext/json/lib/json/pure/parser.rb b/ext/json/lib/json/pure/parser.rb
index 9b30f15c07a..a0ab3075fef 100644
--- a/ext/json/lib/json/pure/parser.rb
+++ b/ext/json/lib/json/pure/parser.rb
@@ -126,20 +126,30 @@ module JSON
if u = UNESCAPE_MAP[$&[1]]
u
else # \uXXXX
- bytes = ''
- i = 0
- while c[6 * i] == ?\\ && c[6 * i + 1] == ?u
- bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
- i += 1
+ res = []
+ stack = nil
+ [c.delete!('\\\\u')].pack("H*").unpack("n*").each do |c|
+ case c
+ when 0xD800..0xDBFF
+ raise JSON::ParserError, "partial character in source" if stack
+ stack = c
+ when 0xDC00..0xDFFF
+ raise JSON::ParserError,
+ "partial character in source" unless (0xD800..0xDBFF).include?(stack)
+ res << (stack << 10) - 0x35fdc00 + c
+ stack = nil
+ else
+ raise JSON::ParserError, "partial character in source" if stack
+ res << c
+ end
end
- JSON::UTF16toUTF8.iconv(bytes)
+ raise JSON::ParserError, "partial character in source" if stack
+ res.pack("U*")
end
end
else
UNPARSED
end
- rescue Iconv::Failure => e
- raise GeneratorError, "Caught #{e.class}: #{e}"
end
def parse_value