Changeset 4787
- Timestamp:
- 08/18/06 09:16:29 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/core.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r4780 r4787 1 1 *SVN* 2 3 * Greatly increased performance of String.to_json, which speeds up RJS considerably on large pages, fixes #3473 [Shugo Maeda] 2 4 3 5 * Detect missing_constants calls from removed modules and fail accordingly. [Nicholas Seckar] trunk/activesupport/lib/active_support/json/encoders/core.rb
r4081 r4787 17 17 'null' 18 18 end 19 20 ESCAPED_CHARS = { 21 "\010" => '\b', 22 "\f" => '\f', 23 "\n" => '\n', 24 "\r" => '\r', 25 "\t" => '\t', 26 '"' => '\"', 27 '\\' => '\\\\' 28 } 19 29 20 30 define_encoder String do |string| 21 returning value = '"' do 22 string.each_char do |char| 23 value << case 24 when char == "\010": '\b' 25 when char == "\f": '\f' 26 when char == "\n": '\n' 27 when char == "\r": '\r' 28 when char == "\t": '\t' 29 when char == '"': '\"' 30 when char == '\\': '\\\\' 31 when char.length > 1: "\\u#{'%04x' % char.unpack('U').first}" 32 else; char 33 end 34 end 35 value << '"' 36 end 31 '"' + string.gsub(/[\010\f\n\r\t"\\]/) { |s| 32 ESCAPED_CHARS[s] 33 }.gsub(/([\xC0-\xDF][\x80-\xBF]| 34 [\xE0-\xEF][\x80-\xBF]{2}| 35 [\xF0-\xF7][\x80-\xBF]{3})+/ux) { |s| 36 s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&') 37 } + '"' 37 38 end 38 39