Permalink
Browse files

move read_* functions to read_cdata.rb

  • Loading branch information...
1 parent b1b8c95 commit 6af562628c2fa66f863eba9b30fe8a4e8004d896 Stefan Lang committed Dec 26, 2008
Showing with 35 additions and 40 deletions.
  1. +2 −20 lib/unicode_utils/combining_class.rb
  2. +1 −18 lib/unicode_utils/conditional_casing.rb
  3. +32 −2 lib/unicode_utils/read_cdata.rb
@@ -1,26 +1,8 @@
# -*- encoding: utf-8 -*-
-module UnicodeUtils
-
- module Impl # :nodoc:
-
- def self.read_combining_class_map
- path = File.join(File.dirname(__FILE__),
- "..", "..", "cdata", "combining_class_map")
- Hash.new.tap { |map|
- File.open(path, "r:US-ASCII:-") do |input|
- buffer = "x" * 6
- buffer.force_encoding(Encoding::US_ASCII)
- cc_buffer = "x" * 2
- cc_buffer.force_encoding(Encoding::US_ASCII)
- while input.read(6, buffer)
- map[buffer.to_i(16)] = input.read(2, cc_buffer).to_i(16)
- end
- end
- }
- end
+require "unicode_utils/read_cdata"
- end
+module UnicodeUtils
COMBINING_CLASS_MAP = Impl.read_combining_class_map() # :nodoc:
@@ -4,6 +4,7 @@
require "unicode_utils/case_ignorable_char_q"
require "unicode_utils/soft_dotted_char_q"
require "unicode_utils/combining_class"
+require "unicode_utils/read_cdata"
module UnicodeUtils
@@ -115,24 +116,6 @@ def after_match?(str, pos)
end
- def self.read_conditional_casings(filename)
- path = File.join(File.dirname(__FILE__), "..", "..", "cdata", filename)
- Hash.new.tap { |cp_map|
- File.open(path, "r:US-ASCII:-") do |input|
- input.each_line { |line|
- line.chomp!
- record = line.split(";")
- cp = record[0].to_i(16)
- mapping = record[1].split(",").map { |c| c.to_i(16) }
- language_id = record[2].empty? ? nil : record[2].to_sym
- context = record[3] && record[3].gsub('_', '')
- casing = Impl.const_get("#{context}ConditionalCasing").new(mapping)
- (cp_map[cp] ||= {})[language_id] = casing
- }
- end
- }
- end
-
CONDITIONAL_UPCASE_MAP =
read_conditional_casings("cond_uc_map")
@@ -4,8 +4,7 @@ module UnicodeUtils
# Absolute path to the directory from which UnicodeUtils loads its
# compiled Unicode data files at runtime.
- CDATA_DIR =
- File.absolute_path(File.join(File.dirname(__FILE__), "..", "..", "cdata"))
+ CDATA_DIR = File.absolute_path(File.join(File.dirname(__FILE__), "..", "..", "cdata"))
module Impl # :nodoc:
@@ -66,6 +65,37 @@ def self.read_names(filename)
}
end
+ def self.read_conditional_casings(filename)
+ Hash.new.tap { |cp_map|
+ open_cdata_file(filename) do |input|
+ input.each_line { |line|
+ line.chomp!
+ record = line.split(";")
+ cp = record[0].to_i(16)
+ mapping = record[1].split(",").map { |c| c.to_i(16) }
+ language_id = record[2].empty? ? nil : record[2].to_sym
+ context = record[3] && record[3].gsub('_', '')
+ casing = Impl.const_get("#{context}ConditionalCasing").new(mapping)
+ (cp_map[cp] ||= {})[language_id] = casing
+ }
+ end
+ }
+ end
+
+ def self.read_combining_class_map
+ Hash.new.tap { |map|
+ open_cdata_file("combining_class_map") do |input|
+ buffer = "x" * 6
+ buffer.force_encoding(Encoding::US_ASCII)
+ cc_buffer = "x" * 2
+ cc_buffer.force_encoding(Encoding::US_ASCII)
+ while input.read(6, buffer)
+ map[buffer.to_i(16)] = input.read(2, cc_buffer).to_i(16)
+ end
+ end
+ }
+ end
+
end
end

0 comments on commit 6af5626

Please sign in to comment.