Got collation working, though it's super slow

This commit is contained in:
Jari Bakken 2010-05-11 00:03:44 +02:00
parent 8556bc7be4
commit 5ff5d67801
2 changed files with 8 additions and 18 deletions

View File

@ -39,8 +39,8 @@ module ICU
array.sort do |a,b| array.sort do |a,b|
Lib.ucol_strcoll( Lib.ucol_strcoll(
@c, @c,
UCharPointer.from_string(a), a.length, UCharPointer.from_string(a), a.size,
UCharPointer.from_string(b), b.length UCharPointer.from_string(b), b.size
) )
end end
end end

View File

@ -1,21 +1,11 @@
require 'iconv'
module ICU module ICU
class UCharPointer < FFI::MemoryPointer class UCharPointer < FFI::MemoryPointer
def self.from_string(str) def self.from_string(str)
bytes = str.bytes.to_a super Iconv.conv("wchar_t", "utf-8", str.encode("UTF-8"))
ptr = new(:uint16, bytes.size)
ptr.put_array_of_uint16(0, bytes)
ptr
end end
end end
# class UCharIteratorPointer < FFI::MemoryPointer
# def self.from_string(str)
# ptr = new(:pointer, 4)
# Lib.uiter_setUTF8(ptr, str, str.length)
# ptr
# end
# end
end end