aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/multibyte/utils.rb
blob: bd6d4bad41b1c18681e24474d28426ab1993a67e (plain) (tree)
1
2
3
4
5
6
7
8
9



                             


                                                                                        

       


                                       






                                                                                             




                                                     

       
   
# encoding: utf-8

module ActiveSupport #:nodoc:
  module Multibyte #:nodoc:
    # Returns a regular expression that matches valid characters in the current encoding
    def self.valid_character
      VALID_CHARACTER[Encoding.default_external.to_s]
    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
    def self.verify!(string)
      raise EncodingError.new("Found characters with invalid encoding") unless verify(string)
    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