1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/json/lib/json/pure/generator.rb (utf8_to_json):

process each unpacked Unicode character.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2008-10-08 08:03:08 +00:00
parent 87259f9a5f
commit cd9f5a1eee
2 changed files with 8 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Wed Oct 8 17:02:21 2008 NARUSE, Yui <naruse@ruby-lang.org>
* ext/json/lib/json/pure/generator.rb (utf8_to_json):
process each unpacked Unicode character.
Wed Oct 8 15:00:22 2008 NARUSE, Yui <naruse@ruby-lang.org>
* ext/json/lib/json/pure/parser.rb

View file

@ -51,8 +51,9 @@ module JSON
[\x80-\xc1\xf5-\xff] # invalid
)/nx) { |c|
c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'"
c = c.unpack("U*")[0]
c > 0xFFFF ? ('\ud%03x\ud%03x' % [0x7C0+c/1024, 0xC00+c%1024]) : ('\u%04x'%c)
c.unpack("U*").map{|c|
c>0xFFFF ? ('\ud%03x\ud%03x'%[0x7C0+c/1024,0xC00+c%1024]) : ('\u%04x'%c)
}.join("")
}
string
end