lib/ffi-icu/lib.rb in ffi-icu-0.0.5 vs lib/ffi-icu/lib.rb in ffi-icu-0.0.6
- old
+ new
@@ -7,14 +7,15 @@
module Lib
extend FFI::Library
VERSIONS = {
- "42" => "_4_2",
- "44" => "_44",
+ "48" => "_48",
+ "46" => "_46",
"45" => "_45",
- "46" => "_46"
+ "44" => "_44",
+ "42" => "_4_2",
}
# FIXME: this is incredibly ugly, figure out some better way
def self.find_icu
suffix = ''
@@ -31,31 +32,38 @@
else
return suffix
end
end
+ libs = nil
+ versions = VERSIONS.keys
+
# ok, try to find it
case ICU.platform
when :osx
ffi_lib "icucore"
when :linux
- versions = VERSIONS.keys
libs = ffi_lib versions.map { |v| "libicui18n.so.#{v}" },
versions.map { |v| "libicutu.so.#{v}" }
- VERSIONS.find do |so_version, func_version|
- if libs.first.name =~ /#{so_version}$/
- suffix = func_version
- end
- end
+ when :windows
+ libs = ffi_lib versions.map { |v| "icuin#{v}.dll" }
else
raise LoadError
end
+ if libs
+ lib_name = libs.first.name
+ version = VERSIONS.find { |object, func| lib_name =~ /#{object}(\.dll)?$/ }
+
+ version or raise "unable to find suffix in #{lib_name}"
+ suffix = version.last
+ end
+
suffix
rescue LoadError => ex
- raise LoadError, "no idea how to load ICU on #{ICU.platform}, patches appreciated! (#{ex.message})"
+ raise LoadError, "no idea how to load ICU on #{ICU.platform.inspect}, patches appreciated! (#{ex.message})"
end
def self.check_error
ptr = FFI::MemoryPointer.new(:int)
ret = yield(ptr)
@@ -96,12 +104,12 @@
suffix = find_icu()
attach_function :u_errorName, "u_errorName#{suffix}", [:int], :string
attach_function :uenum_count, "uenum_count#{suffix}", [:pointer, :pointer], :int
- attach_function :uenum_close, "uenum_close#{suffix}", [:pointer], :void
- attach_function :uenum_next, "uenum_next#{suffix}", [:pointer, :pointer, :pointer], :string
+ attach_function :uenum_close, "uenum_close#{suffix}", [:pointer], :void
+ attach_function :uenum_next, "uenum_next#{suffix}", [:pointer, :pointer, :pointer], :string
attach_function :u_charsToUChars, "u_charsToUChars#{suffix}", [:string, :pointer, :int32_t], :void
attach_function :u_UCharsToChars, "u_UCharsToChars#{suffix}", [:pointer, :string, :int32_t], :void
# CharDet
#
@@ -124,15 +132,15 @@
# Collation
#
# http://icu-project.org/apiref/icu4c/ucol_8h.html
#
- attach_function :ucol_open, "ucol_open#{suffix}", [:string, :pointer], :pointer
- attach_function :ucol_close, "ucol_close#{suffix}", [:pointer], :void
- attach_function :ucol_strcoll, "ucol_strcoll#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :int
- attach_function :ucol_getKeywords, "ucol_getKeywords#{suffix}", [:pointer], :pointer
- attach_function :ucol_getKeywordValues, "ucol_getKeywordValues#{suffix}", [:string, :pointer], :pointer
+ attach_function :ucol_open, "ucol_open#{suffix}", [:string, :pointer], :pointer
+ attach_function :ucol_close, "ucol_close#{suffix}", [:pointer], :void
+ attach_function :ucol_strcoll, "ucol_strcoll#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :int
+ attach_function :ucol_getKeywords, "ucol_getKeywords#{suffix}", [:pointer], :pointer
+ attach_function :ucol_getKeywordValues, "ucol_getKeywordValues#{suffix}", [:string, :pointer], :pointer
attach_function :ucol_getAvailable, "ucol_getAvailable#{suffix}", [:int32_t], :string
attach_function :ucol_countAvailable, "ucol_countAvailable#{suffix}", [], :int32_t
attach_function :ucol_getLocale, "ucol_getLocale#{suffix}", [:pointer, :int, :pointer], :string
attach_function :ucol_greater, "ucol_greater#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
attach_function :ucol_greaterOrEqual, "ucol_greaterOrEqual#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
@@ -186,9 +194,11 @@
attach_function :unorm_normalize, "unorm_normalize#{suffix}", [:pointer, :int32_t, :normalization_mode, :int32_t, :pointer, :int32_t, :pointer], :int32_t
#
# Text Boundary Analysis
+ #
+ # http://icu-project.org/apiref/icu4c/ubrk_8h.html
#
enum :iterator_type, [ :character, :word, :line, :sentence, :title]
enum :word_break, [ :none, 0,
:none_limit, 100,