summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-08 08:03:08 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-08 08:03:08 +0000
commitcd9f5a1eeeeb423523940d652a4a8957be984b4a (patch)
tree7dfa633acd33ac29e3a87196f3b957dc71334a02 /ext/json
parent87259f9a5f19eb5c568079c33360e5fd15772938 (diff)
* 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
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/lib/json/pure/generator.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/ext/json/lib/json/pure/generator.rb b/ext/json/lib/json/pure/generator.rb
index abc24bf..9c7cfac 100644
--- a/ext/json/lib/json/pure/generator.rb
+++ b/ext/json/lib/json/pure/generator.rb
@@ -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