Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Faster 1.8 codepoint encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Aug 3, 2011
1 parent d2bb6c7 commit 22ae39a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/execjs/external_runtime.rb
Expand Up @@ -74,9 +74,11 @@ def encode_unicode_codepoints(str)
end
else
def encode_unicode_codepoints(str)
str.unpack("U*").map { |b|
b >= 128 ? "\\u%04x" % b : b.chr
}.join("")
str.gsub(/([\xC0-\xDF][\x80-\xBF]|
[\xE0-\xEF][\x80-\xBF]{2}|
[\xF0-\xF7][\x80-\xBF]{3})+/nx) do |ch|
"\\u%04x" % ch.unpack("U*")
end
end
end
end
Expand Down

0 comments on commit 22ae39a

Please sign in to comment.