~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/multibyte.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# encoding: utf-8
2
 
 
3
 
module ActiveSupport #:nodoc:
4
 
  module Multibyte
5
 
    # A list of all available normalization forms. See http://www.unicode.org/reports/tr15/tr15-29.html for more
6
 
    # information about normalization.
7
 
    NORMALIZATION_FORMS = [:c, :kc, :d, :kd]
8
 
 
9
 
    # The Unicode version that is supported by the implementation
10
 
    UNICODE_VERSION = '5.1.0'
11
 
 
12
 
    # The default normalization used for operations that require normalization. It can be set to any of the
13
 
    # normalizations in NORMALIZATION_FORMS.
14
 
    #
15
 
    # Example:
16
 
    #   ActiveSupport::Multibyte.default_normalization_form = :c
17
 
    mattr_accessor :default_normalization_form
18
 
    self.default_normalization_form = :kc
19
 
 
20
 
    # The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy
21
 
    # class so you can support other encodings. See the ActiveSupport::Multibyte::Chars implementation for
22
 
    # an example how to do this.
23
 
    #
24
 
    # Example:
25
 
    #   ActiveSupport::Multibyte.proxy_class = CharsForUTF32
26
 
    def self.proxy_class=(klass)
27
 
      @proxy_class = klass
28
 
    end
29
 
 
30
 
    # Returns the currect proxy class
31
 
    def self.proxy_class
32
 
      @proxy_class ||= ActiveSupport::Multibyte::Chars
33
 
    end
34
 
 
35
 
    # Regular expressions that describe valid byte sequences for a character
36
 
    VALID_CHARACTER = {
37
 
      # Borrowed from the Kconv library by Shinji KONO - (also as seen on the W3C site)
38
 
      'UTF-8' => /\A(?:
39
 
                  [\x00-\x7f]                                         |
40
 
                  [\xc2-\xdf] [\x80-\xbf]                             |
41
 
                  \xe0        [\xa0-\xbf] [\x80-\xbf]                 |
42
 
                  [\xe1-\xef] [\x80-\xbf] [\x80-\xbf]                 |
43
 
                  \xf0        [\x90-\xbf] [\x80-\xbf] [\x80-\xbf]     |
44
 
                  [\xf1-\xf3] [\x80-\xbf] [\x80-\xbf] [\x80-\xbf]     |
45
 
                  \xf4        [\x80-\x8f] [\x80-\xbf] [\x80-\xbf])\z /xn,
46
 
      # Quick check for valid Shift-JIS characters, disregards the odd-even pairing
47
 
      'Shift_JIS' => /\A(?:
48
 
                  [\x00-\x7e \xa1-\xdf]                                     |
49
 
                  [\x81-\x9f \xe0-\xef] [\x40-\x7e \x80-\x9e \x9f-\xfc])\z /xn
50
 
    }
51
 
  end
52
 
end
53
 
 
54
 
require 'active_support/multibyte/chars'
55
 
require 'active_support/multibyte/exceptions'
56
 
require 'active_support/multibyte/unicode_database'
57
 
require 'active_support/multibyte/utils'