Sha256: 64f22f65727a01677e7eff0a364cdf37e8a15c0d2bd58f86c35229d818451b6f

Contents?: true

Size: 1.57 KB

Versions: 23

Compression:

Stored size: 1.57 KB

Contents

# encoding: utf-8

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_internal.to_s]
      end
    else
      def self.valid_character
        case $KCODE
        when 'UTF8'
          VALID_CHARACTER['UTF-8']
        when 'SJIS'
          VALID_CHARACTER['Shift_JIS']
        end
      end
    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
          for c in string.split(//)
            return false unless valid_character.match(c)
          end
        end
        true
      end
    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

    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
          stripped = []; for c in string.split(//)
            stripped << c if valid_character.match(c)
          end; stripped.join
        else
          string
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 6 rubygems

Version Path
radiantcms-couchrest_model-0.2.4 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiantcms-couchrest_model-0.2.2 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiantcms-couchrest_model-0.2.1 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiantcms-couchrest_model-0.2 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiantcms-couchrest_model-0.1.9 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiantcms-couchrest_model-0.1.8 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiantcms-couchrest_model-0.1.7 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiantcms-couchrest_model-0.1.6 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiantcms-couchrest_model-0.1.5 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
radiant-0.8.2 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
ginst-2009.12.8 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
ginst-2009.11.24 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
ginst-2009.11.23 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
ginst-2.0.1 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
ginst-2.0.0 vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
gemstreamer-1.2.0 spec/assets/testapp/vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
gemstreamer-1.1.1 spec/assets/testapp/vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
gemstreamer-1.1.0 spec/assets/testapp/vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
gemstreamer-1.0.0 spec/assets/testapp/vendor/rails/activesupport/lib/active_support/multibyte/utils.rb
gemstreamer-0.0.0 spec/assets/testapp/vendor/rails/activesupport/lib/active_support/multibyte/utils.rb