Module: ICU::Lib
- Extended by:
- FFI::Library
- Defined in:
- lib/ffi-icu/lib.rb
Defined Under Namespace
Classes: UParseError, UTransPosition
Constant Summary collapse
- VERSIONS =
{ "48" => "_48", "46" => "_46", "45" => "_45", "44" => "_44", "42" => "_4_2", }
Class Method Summary collapse
- .check_error ⇒ Object
- .enum_ptr_to_array(enum_ptr) ⇒ Object
-
.find_icu ⇒ Object
FIXME: this is incredibly ugly, figure out some better way.
- .not_available(func_name) ⇒ Object
Class Method Details
.check_error ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ffi-icu/lib.rb', line 67 def self.check_error ptr = FFI::MemoryPointer.new(:int) ret = yield(ptr) error_code = ptr.read_int if error_code > 0 name = Lib.u_errorName error_code if name == "U_BUFFER_OVERFLOW_ERROR" raise BufferOverflowError else raise Error, name end elsif error_code < 0 warn "ffi-icu: #{Lib.u_errorName error_code}" end ret end |
.enum_ptr_to_array(enum_ptr) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ffi-icu/lib.rb', line 86 def self.enum_ptr_to_array(enum_ptr) length = check_error do |status| uenum_count(enum_ptr, status) end len = FFI::MemoryPointer.new(:int) (0...length).map do |idx| check_error { |st| uenum_next(enum_ptr, len, st) } end end |
.find_icu ⇒ Object
FIXME: this is incredibly ugly, figure out some better way
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ffi-icu/lib.rb', line 20 def self.find_icu suffix = '' # let the user tell us where the lib is if ENV['FFI_ICU_LIB'] libs = ENV['FFI_ICU_LIB'].split(",") ffi_lib(*libs) if ENV['FFI_ICU_VERSION_SUFFIX'] return ENV['FFI_ICU_VERSION_SUFFIX'] elsif num = libs.first[/\d+$/] return num.split(//).join("_") 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 libs = ffi_lib versions.map { |v| "libicui18n.so.#{v}" }, versions.map { |v| "libicutu.so.#{v}" } 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.inspect}, patches appreciated! (#{ex.})" end |