module Mail::Multibyte
def self.clean(string)
Removes all invalid characters from the string.
def self.clean(string) string end
def self.clean(string)
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
def self.proxy_class
def self.proxy_class @proxy_class ||= Mail::Multibyte::Chars end
def self.proxy_class=(klass)
Example:
an example how to do this.
class so you can support other encodings. See the Mail::Multibyte::Chars implementation for
The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy
def self.proxy_class=(klass) @proxy_class = klass end
def self.valid_character
def self.valid_character VALID_CHARACTER[Encoding.default_external.to_s] end
def self.valid_character
def self.valid_character case $KCODE when 'UTF8' VALID_CHARACTER['UTF-8'] when 'SJIS' VALID_CHARACTER['Shift_JIS'] end end
def self.verify(string)
def self.verify(string) string.valid_encoding? end
def self.verify(string)
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
def self.verify!(string)
def self.verify!(string) raise EncodingError.new("Found characters with invalid encoding") unless verify(string) end