3
module ActiveSupport #:nodoc:
4
module Multibyte #:nodoc:
5
# Holds data about a codepoint in the Unicode database
7
attr_accessor :code, :combining_class, :decomp_type, :decomp_mapping, :uppercase_mapping, :lowercase_mapping
10
# Holds static data from the Unicode database
12
ATTRIBUTES = :codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252
14
attr_writer(*ATTRIBUTES)
17
@codepoints = Hash.new(Codepoint.new)
18
@composition_exclusion = []
24
# Lazy load the Unicode database so it's only loaded when it's actually used
25
ATTRIBUTES.each do |attr_name|
26
class_eval(<<-EOS, __FILE__, __LINE__)
27
def #{attr_name} # def codepoints
29
@#{attr_name} # @codepoints
34
# Loads the Unicode database and returns all the internal objects of UnicodeDatabase.
37
@codepoints, @composition_exclusion, @composition_map, @boundary, @cp1252 = File.open(self.class.filename, 'rb') { |f| Marshal.load f.read }
39
raise IOError.new("Couldn't load the Unicode tables for UTF8Handler (#{e.message}), ActiveSupport::Multibyte is unusable")
42
# Redefine the === method so we can write shorter rules for grapheme cluster breaks
43
@boundary.each do |k,_|
44
@boundary[k].instance_eval do
46
detect { |i| i === other } ? true : false
48
end if @boundary[k].kind_of?(Array)
51
# define attr_reader methods for the instance variables
53
attr_reader(*ATTRIBUTES)
57
# Returns the directory in which the data files are stored
59
File.dirname(__FILE__) + '/../values/'
62
# Returns the filename for the data file for this version
64
File.expand_path File.join(dirname, "unicode_tables.dat")
69
UCD = UnicodeDatabase.new
b'\\ No newline at end of file'