diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2011-12-25 14:34:58 +0300 |
---|---|---|
committer | Sergey Nartimov <just.lest@gmail.com> | 2011-12-25 14:34:58 +0300 |
commit | 1e9e88fcd335c7d5a99159d592c3e1b605510a16 (patch) | |
tree | d4ccf417d4ed7c999b574ba941cf9ecb68f7882c /activesupport/lib/active_support/multibyte | |
parent | 4c1701c0ca6ae77a8274f59460751d1b1d83ce1b (diff) | |
download | rails-1e9e88fcd335c7d5a99159d592c3e1b605510a16.tar.gz rails-1e9e88fcd335c7d5a99159d592c3e1b605510a16.tar.bz2 rails-1e9e88fcd335c7d5a99159d592c3e1b605510a16.zip |
remove checks for encodings availability
Diffstat (limited to 'activesupport/lib/active_support/multibyte')
-rw-r--r-- | activesupport/lib/active_support/multibyte/chars.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/multibyte/utils.rb | 55 |
2 files changed, 12 insertions, 47 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index ba35b515f2..dcc176e93f 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -282,9 +282,7 @@ module ActiveSupport #:nodoc: return nil if byte_offset.nil? return 0 if @wrapped_string == '' - if @wrapped_string.respond_to?(:force_encoding) - @wrapped_string = @wrapped_string.dup.force_encoding(Encoding::ASCII_8BIT) - end + @wrapped_string = @wrapped_string.dup.force_encoding(Encoding::ASCII_8BIT) begin @wrapped_string[0...byte_offset].unpack('U*').length diff --git a/activesupport/lib/active_support/multibyte/utils.rb b/activesupport/lib/active_support/multibyte/utils.rb index 94b393cee2..bd6d4bad41 100644 --- a/activesupport/lib/active_support/multibyte/utils.rb +++ b/activesupport/lib/active_support/multibyte/utils.rb @@ -2,36 +2,14 @@ module ActiveSupport #:nodoc: module Multibyte #:nodoc: - if Kernel.const_defined?(:Encoding) - # Returns a regular expression that matches valid characters in the current encoding - def self.valid_character - VALID_CHARACTER[Encoding.default_external.to_s] - end - else - def self.valid_character - case $KCODE - when 'UTF8' - VALID_CHARACTER['UTF-8'] - when 'SJIS' - VALID_CHARACTER['Shift_JIS'] - end - end + # Returns a regular expression that matches valid characters in the current encoding + def self.valid_character + VALID_CHARACTER[Encoding.default_external.to_s] end - if 'string'.respond_to?(:valid_encoding?) - # Verifies the encoding of a string - def self.verify(string) - string.valid_encoding? - end - else - def self.verify(string) - if expression = valid_character - # Splits the string on character boundaries, which are determined based on $KCODE. - string.split(//).all? { |c| expression =~ c } - else - true - end - end + # Verifies the encoding of a string + def self.verify(string) + string.valid_encoding? end # Verifies the encoding of the string and raises an exception when it's not valid @@ -39,22 +17,11 @@ module ActiveSupport #:nodoc: raise EncodingError.new("Found characters with invalid encoding") unless verify(string) end - if 'string'.respond_to?(:force_encoding) - # Removes all invalid characters from the string. - # - # Note: this method is a no-op in Ruby 1.9 - def self.clean(string) - string - end - else - def self.clean(string) - if expression = valid_character - # Splits the string on character boundaries, which are determined based on $KCODE. - string.split(//).grep(expression).join - else - string - end - end + # Removes all invalid characters from the string. + # + # Note: this method is a no-op in Ruby 1.9 + def self.clean(string) + string end end end |