mirror of https://github.com/erickguan/ffi-icu.git
Revert "Two collator improvements"
This commit is contained in:
parent
67ed2859d0
commit
b5e740471e
|
@ -1,38 +1,6 @@
|
|||
module ICU
|
||||
module Collation
|
||||
|
||||
ATTRIBUTES = {
|
||||
french_collation: 0,
|
||||
alternate_handling: 1,
|
||||
case_first: 2,
|
||||
case_level: 3,
|
||||
normalization_mode: 4,
|
||||
strength: 5,
|
||||
hiragana_quaternary_mode: 6,
|
||||
numeric_collation: 7,
|
||||
}.freeze
|
||||
|
||||
ATTRIBUTE_VALUES = {
|
||||
nil => -1,
|
||||
primary: 0,
|
||||
secondary: 1,
|
||||
default_strength: 2,
|
||||
tertiary: 2,
|
||||
quaternary: 3,
|
||||
identical: 15,
|
||||
|
||||
false => 16,
|
||||
true => 17,
|
||||
|
||||
shifted: 20,
|
||||
non_ignorable: 21,
|
||||
|
||||
lower_first: 24,
|
||||
upper_first: 25,
|
||||
}.freeze
|
||||
|
||||
ATTRIBUTE_VALUES_INVERSE = Hash[ATTRIBUTE_VALUES.map {|k,v| [v, k]}].freeze
|
||||
|
||||
def self.collate(locale, arr)
|
||||
Collator.new(locale).collate(arr)
|
||||
end
|
||||
|
@ -112,44 +80,10 @@ module ICU
|
|||
def rules
|
||||
@rules ||= begin
|
||||
length = FFI::MemoryPointer.new(:int)
|
||||
ptr = Lib.ucol_getRules(@c, length)
|
||||
ptr = ICU::Lib.ucol_getRules(@c, length)
|
||||
ptr.read_array_of_uint16(length.read_int).pack("U*")
|
||||
end
|
||||
end
|
||||
|
||||
def collation_key(string)
|
||||
ptr = UCharPointer.from_string(string)
|
||||
size = Lib.ucol_getSortKey(@c, ptr, string.jlength, nil, 0)
|
||||
buffer = FFI::MemoryPointer.new(:char, size)
|
||||
Lib.ucol_getSortKey(@c, ptr, string.jlength, buffer, size)
|
||||
buffer.read_bytes(size - 1)
|
||||
end
|
||||
|
||||
def [](attribute)
|
||||
ATTRIBUTE_VALUES_INVERSE[Lib.check_error do |error|
|
||||
Lib.ucol_getAttribute(@c, ATTRIBUTES[attribute], error)
|
||||
end]
|
||||
end
|
||||
|
||||
def []=(attribute, value)
|
||||
Lib.check_error do |error|
|
||||
Lib.ucol_setAttribute(@c, ATTRIBUTES[attribute], ATTRIBUTE_VALUES[value], error)
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
# create friendly named methods for setting attributes
|
||||
ATTRIBUTES.each_key do |attribute|
|
||||
class_eval <<-CODE
|
||||
def #{attribute}
|
||||
self[:#{attribute}]
|
||||
end
|
||||
|
||||
def #{attribute}=(value)
|
||||
self[:#{attribute}] = value
|
||||
end
|
||||
CODE
|
||||
end
|
||||
end # Collator
|
||||
|
||||
end # Collate
|
||||
|
|
|
@ -297,10 +297,6 @@ module ICU
|
|||
attach_function :ucol_greaterOrEqual, "ucol_greaterOrEqual#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
|
||||
attach_function :ucol_equal, "ucol_equal#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
|
||||
attach_function :ucol_getRules, "ucol_getRules#{suffix}", [:pointer, :pointer], :pointer
|
||||
attach_function :ucol_getSortKey, "ucol_getSortKey#{suffix}", [:pointer, :pointer, :int, :pointer, :int], :int
|
||||
attach_function :ucol_getAttribute, "ucol_getAttribute#{suffix}", [:pointer, :int, :pointer], :int
|
||||
attach_function :ucol_setAttribute, "ucol_setAttribute#{suffix}", [:pointer, :int, :int, :pointer], :void
|
||||
|
||||
|
||||
# Transliteration
|
||||
#
|
||||
|
|
|
@ -58,27 +58,6 @@ module ICU
|
|||
expect(collator.rules).to include('ö<<<Ö')
|
||||
end
|
||||
|
||||
it "returns usable collation keys" do
|
||||
collator.collation_key("abc").should be < collator.collation_key("xyz")
|
||||
end
|
||||
|
||||
context "attributes" do
|
||||
it "can set and get normalization_mode" do
|
||||
collator.normalization_mode = true
|
||||
collator.normalization_mode.should be_true
|
||||
|
||||
collator[:normalization_mode].should be_true
|
||||
collator[:normalization_mode] = false
|
||||
collator.normalization_mode.should be_false
|
||||
|
||||
collator.case_first.should be_false
|
||||
collator.case_first = :lower_first
|
||||
collator.case_first.should == :lower_first
|
||||
|
||||
collator.strength = :tertiary
|
||||
collator.strength.should == :tertiary
|
||||
end
|
||||
end
|
||||
end
|
||||
end # Collate
|
||||
end # ICU
|
||||
|
|
Loading…
Reference in New Issue