Module: ActiveSupport::Multibyte
- Defined in:
- activesupport/lib/active_support/multibyte/chars.rb,
activesupport/lib/active_support/multibyte.rb,
activesupport/lib/active_support/multibyte/utils.rb,
activesupport/lib/active_support/multibyte/unicode.rb,
activesupport/lib/active_support/multibyte/exceptions.rb
Overview
:nodoc:
Constant Summary
Class Method Summary (collapse)
-
+ (Object) clean(string)
Removes all invalid characters from the string.
-
+ (Object) proxy_class
Returns the current proxy class.
-
+ (Object) proxy_class=(klass)
The proxy class returned when calling mb_chars.
-
+ (Object) valid_character
Returns a regular expression that matches valid characters in the current encoding.
-
+ (Object) verify(string)
Verifies the encoding of a string.
-
+ (Object) verify!(string)
Verifies the encoding of the string and raises an exception when it's not valid.
Class Method Details
+ (Object) clean(string)
Removes all invalid characters from the string.
Note: this method is a no-op in Ruby 1.9
46 47 48 49 50 51 52 53 |
# File 'activesupport/lib/active_support/multibyte/utils.rb', line 46 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 |
+ (Object) proxy_class
Returns the current proxy class
21 22 23 |
# File 'activesupport/lib/active_support/multibyte.rb', line 21 def self.proxy_class @proxy_class ||= ActiveSupport::Multibyte::Chars end |
+ (Object) proxy_class=(klass)
The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy class so you can support other encodings. See the ActiveSupport::Multibyte::Chars implementation for an example how to do this.
Example:
ActiveSupport::Multibyte.proxy_class = CharsForUTF32
16 17 18 |
# File 'activesupport/lib/active_support/multibyte.rb', line 16 def self.proxy_class=(klass) @proxy_class = klass end |
+ (Object) valid_character
Returns a regular expression that matches valid characters in the current encoding
7 8 9 10 11 12 13 14 |
# File 'activesupport/lib/active_support/multibyte/utils.rb', line 7 def self.valid_character case $KCODE when 'UTF8' VALID_CHARACTER['UTF-8'] when 'SJIS' VALID_CHARACTER['Shift_JIS'] end end |
+ (Object) verify(string)
Verifies the encoding of a string
23 24 25 26 27 28 29 30 |
# File 'activesupport/lib/active_support/multibyte/utils.rb', line 23 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 |
+ (Object) verify!(string)
Verifies the encoding of the string and raises an exception when it's not valid
38 39 40 |
# File 'activesupport/lib/active_support/multibyte/utils.rb', line 38 def self.verify!(string) raise EncodingError.new("Found characters with invalid encoding") unless verify(string) end |