ffi-icu 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ffi-icu/lib.rb CHANGED
@@ -10,7 +10,9 @@ module ICU
10
10
 
11
11
  VERSIONS = {
12
12
  "42" => "_4_2",
13
- "44" => "_44"
13
+ "44" => "_44",
14
+ "45" => "_45",
15
+ "46" => "_46"
14
16
  }
15
17
 
16
18
  # FIXME: this is incredibly ugly, figure out some better way
@@ -37,8 +39,8 @@ module ICU
37
39
  ffi_lib "icucore"
38
40
  when :linux
39
41
  versions = VERSIONS.keys
40
- libs = ffi_lib versions.map { |v| "libicui18n.so.#{v}"},
41
- versions.map { |v| "libicutu.so.#{v}"}
42
+ libs = ffi_lib versions.map { |v| "libicui18n.so.#{v}" },
43
+ versions.map { |v| "libicutu.so.#{v}" }
42
44
 
43
45
  VERSIONS.find do |so_version, func_version|
44
46
  if libs.first.name =~ /#{so_version}$/
@@ -46,10 +48,12 @@ module ICU
46
48
  end
47
49
  end
48
50
  else
49
- raise "no idea how to load ICU on #{ICU.platform}, patches appreciated!"
51
+ raise LoadError
50
52
  end
51
53
 
52
54
  suffix
55
+ rescue LoadError => ex
56
+ raise LoadError, "no idea how to load ICU on #{ICU.platform}, patches appreciated! (#{ex.message})"
53
57
  end
54
58
 
55
59
  def self.check_error
@@ -92,47 +96,47 @@ module ICU
92
96
 
93
97
  suffix = find_icu()
94
98
 
95
- attach_function :u_errorName, "u_errorName#{suffix}", [:int], :string
96
- attach_function :uenum_count, "uenum_count#{suffix}", [:pointer, :pointer], :int
97
- attach_function :uenum_close, "uenum_close#{suffix}", [:pointer], :void
98
- attach_function :uenum_next, "uenum_next#{suffix}", [:pointer, :pointer, :pointer], :string
99
- attach_function :u_charsToUChars, "u_charsToUChars#{suffix}", [:string, :pointer, :int32_t], :void
100
- attach_function :u_UCharsToChars, "u_UCharsToChars#{suffix}", [:pointer, :string, :int32_t], :void
99
+ attach_function :u_errorName, "u_errorName#{suffix}", [:int], :string
100
+ attach_function :uenum_count, "uenum_count#{suffix}", [:pointer, :pointer], :int
101
+ attach_function :uenum_close, "uenum_close#{suffix}", [:pointer], :void
102
+ attach_function :uenum_next, "uenum_next#{suffix}", [:pointer, :pointer, :pointer], :string
103
+ attach_function :u_charsToUChars, "u_charsToUChars#{suffix}", [:string, :pointer, :int32_t], :void
104
+ attach_function :u_UCharsToChars, "u_UCharsToChars#{suffix}", [:pointer, :string, :int32_t], :void
101
105
 
102
106
  # CharDet
103
107
  #
104
108
  # http://icu-project.org/apiref/icu4c/ucsdet_8h.html
105
109
  #
106
110
 
107
- attach_function :ucsdet_open, "ucsdet_open#{suffix}", [:pointer], :pointer
108
- attach_function :ucsdet_close, "ucsdet_close#{suffix}", [:pointer], :void
109
- attach_function :ucsdet_setText, "ucsdet_setText#{suffix}", [:pointer, :string, :int32_t, :pointer], :void
110
- attach_function :ucsdet_setDeclaredEncoding, "ucsdet_setDeclaredEncoding#{suffix}", [:pointer, :string, :int32_t, :pointer], :void
111
- attach_function :ucsdet_detect, "ucsdet_detect#{suffix}", [:pointer, :pointer], :pointer
112
- attach_function :ucsdet_detectAll, "ucsdet_detectAll#{suffix}", [:pointer, :pointer, :pointer], :pointer
113
- attach_function :ucsdet_getName, "ucsdet_getName#{suffix}", [:pointer, :pointer], :string
114
- attach_function :ucsdet_getConfidence, "ucsdet_getConfidence#{suffix}", [:pointer, :pointer], :int32_t
115
- attach_function :ucsdet_getLanguage, "ucsdet_getLanguage#{suffix}", [:pointer, :pointer], :string
116
- attach_function :ucsdet_getAllDetectableCharsets, "ucsdet_getAllDetectableCharsets#{suffix}", [:pointer, :pointer], :pointer
117
- attach_function :ucsdet_isInputFilterEnabled, "ucsdet_isInputFilterEnabled#{suffix}", [:pointer], :bool
118
- attach_function :ucsdet_enableInputFilter, "ucsdet_enableInputFilter#{suffix}", [:pointer, :bool], :bool
111
+ attach_function :ucsdet_open, "ucsdet_open#{suffix}", [:pointer], :pointer
112
+ attach_function :ucsdet_close, "ucsdet_close#{suffix}", [:pointer], :void
113
+ attach_function :ucsdet_setText, "ucsdet_setText#{suffix}", [:pointer, :string, :int32_t, :pointer], :void
114
+ attach_function :ucsdet_setDeclaredEncoding, "ucsdet_setDeclaredEncoding#{suffix}", [:pointer, :string, :int32_t, :pointer], :void
115
+ attach_function :ucsdet_detect, "ucsdet_detect#{suffix}", [:pointer, :pointer], :pointer
116
+ attach_function :ucsdet_detectAll, "ucsdet_detectAll#{suffix}", [:pointer, :pointer, :pointer], :pointer
117
+ attach_function :ucsdet_getName, "ucsdet_getName#{suffix}", [:pointer, :pointer], :string
118
+ attach_function :ucsdet_getConfidence, "ucsdet_getConfidence#{suffix}", [:pointer, :pointer], :int32_t
119
+ attach_function :ucsdet_getLanguage, "ucsdet_getLanguage#{suffix}", [:pointer, :pointer], :string
120
+ attach_function :ucsdet_getAllDetectableCharsets, "ucsdet_getAllDetectableCharsets#{suffix}", [:pointer, :pointer], :pointer
121
+ attach_function :ucsdet_isInputFilterEnabled, "ucsdet_isInputFilterEnabled#{suffix}", [:pointer], :bool
122
+ attach_function :ucsdet_enableInputFilter, "ucsdet_enableInputFilter#{suffix}", [:pointer, :bool], :bool
119
123
 
120
124
  # Collation
121
125
  #
122
126
  # http://icu-project.org/apiref/icu4c/ucol_8h.html
123
127
  #
124
128
 
125
- attach_function :ucol_open, "ucol_open#{suffix}", [:string, :pointer], :pointer
126
- attach_function :ucol_close, "ucol_close#{suffix}", [:pointer], :void
127
- attach_function :ucol_strcoll, "ucol_strcoll#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :int
128
- attach_function :ucol_getKeywords, "ucol_getKeywords#{suffix}", [:pointer], :pointer
129
- attach_function :ucol_getKeywordValues, "ucol_getKeywordValues#{suffix}", [:string, :pointer], :pointer
130
- attach_function :ucol_getAvailable, "ucol_getAvailable#{suffix}", [:int32_t], :string
131
- attach_function :ucol_countAvailable, "ucol_countAvailable#{suffix}", [], :int32_t
132
- attach_function :ucol_getLocale, "ucol_getLocale#{suffix}", [:pointer, :int, :pointer], :string
133
- attach_function :ucol_greater, "ucol_greater#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
134
- attach_function :ucol_greaterOrEqual, "ucol_greaterOrEqual#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
135
- attach_function :ucol_equal, "ucol_equal#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
129
+ attach_function :ucol_open, "ucol_open#{suffix}", [:string, :pointer], :pointer
130
+ attach_function :ucol_close, "ucol_close#{suffix}", [:pointer], :void
131
+ attach_function :ucol_strcoll, "ucol_strcoll#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :int
132
+ attach_function :ucol_getKeywords, "ucol_getKeywords#{suffix}", [:pointer], :pointer
133
+ attach_function :ucol_getKeywordValues, "ucol_getKeywordValues#{suffix}", [:string, :pointer], :pointer
134
+ attach_function :ucol_getAvailable, "ucol_getAvailable#{suffix}", [:int32_t], :string
135
+ attach_function :ucol_countAvailable, "ucol_countAvailable#{suffix}", [], :int32_t
136
+ attach_function :ucol_getLocale, "ucol_getLocale#{suffix}", [:pointer, :int, :pointer], :string
137
+ attach_function :ucol_greater, "ucol_greater#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
138
+ attach_function :ucol_greaterOrEqual, "ucol_greaterOrEqual#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
139
+ attach_function :ucol_equal, "ucol_equal#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
136
140
 
137
141
  # Transliteration
138
142
  #
@@ -160,11 +164,11 @@ module ICU
160
164
 
161
165
  enum :trans_direction, [:forward, :reverse]
162
166
 
163
- attach_function :utrans_openIDs, "utrans_openIDs#{suffix}", [:pointer], :pointer
164
- attach_function :utrans_openU, "utrans_openU#{suffix}", [:pointer, :int32_t, :trans_direction, :pointer, :int32_t, :pointer, :pointer], :pointer
165
- attach_function :utrans_open, "utrans_open#{suffix}", [:string, :trans_direction, :pointer, :int32_t, :pointer, :pointer], :pointer
166
- attach_function :utrans_close, "utrans_close#{suffix}", [:pointer], :void
167
- attach_function :utrans_transUChars, "utrans_transUChars#{suffix}", [:pointer, :pointer, :pointer, :int32_t, :int32_t, :pointer, :pointer], :void
167
+ attach_function :utrans_openIDs, "utrans_openIDs#{suffix}", [:pointer], :pointer
168
+ attach_function :utrans_openU, "utrans_openU#{suffix}", [:pointer, :int32_t, :trans_direction, :pointer, :int32_t, :pointer, :pointer], :pointer
169
+ attach_function :utrans_open, "utrans_open#{suffix}", [:string, :trans_direction, :pointer, :int32_t, :pointer, :pointer], :pointer
170
+ attach_function :utrans_close, "utrans_close#{suffix}", [:pointer], :void
171
+ attach_function :utrans_transUChars, "utrans_transUChars#{suffix}", [:pointer, :pointer, :pointer, :int32_t, :int32_t, :pointer, :pointer], :void
168
172
 
169
173
  # Normalization
170
174
  #
@@ -199,21 +203,21 @@ module ICU
199
203
  :ideo_limit, 400
200
204
  ]
201
205
 
202
- attach_function :ubrk_countAvailable, "ubrk_countAvailable#{suffix}", [], :int32_t
203
- attach_function :ubrk_getAvailable, "ubrk_getAvailable#{suffix}", [:int32_t], :string
204
-
205
- attach_function :ubrk_open, "ubrk_open#{suffix}", [:iterator_type, :string, :pointer, :int32_t, :pointer], :pointer
206
- attach_function :ubrk_close, "ubrk_close#{suffix}", [:pointer], :void
207
- attach_function :ubrk_setText, "ubrk_setText#{suffix}", [:pointer, :pointer, :int32_t, :pointer], :void
208
- attach_function :ubrk_current, "ubrk_current#{suffix}", [:pointer], :int32_t
209
- attach_function :ubrk_next, "ubrk_next#{suffix}", [:pointer], :int32_t
210
- attach_function :ubrk_previous, "ubrk_previous#{suffix}", [:pointer], :int32_t
211
- attach_function :ubrk_first, "ubrk_first#{suffix}", [:pointer], :int32_t
212
- attach_function :ubrk_last, "ubrk_last#{suffix}", [:pointer], :int32_t
213
-
214
- attach_function :ubrk_preceding, "ubrk_preceding#{suffix}", [:pointer, :int32_t], :int32_t
215
- attach_function :ubrk_following, "ubrk_following#{suffix}", [:pointer, :int32_t], :int32_t
216
- attach_function :ubrk_isBoundary, "ubrk_isBoundary#{suffix}", [:pointer, :int32_t], :int32_t
206
+ attach_function :ubrk_countAvailable, "ubrk_countAvailable#{suffix}", [], :int32_t
207
+ attach_function :ubrk_getAvailable, "ubrk_getAvailable#{suffix}", [:int32_t], :string
208
+
209
+ attach_function :ubrk_open, "ubrk_open#{suffix}", [:iterator_type, :string, :pointer, :int32_t, :pointer], :pointer
210
+ attach_function :ubrk_close, "ubrk_close#{suffix}", [:pointer], :void
211
+ attach_function :ubrk_setText, "ubrk_setText#{suffix}", [:pointer, :pointer, :int32_t, :pointer], :void
212
+ attach_function :ubrk_current, "ubrk_current#{suffix}", [:pointer], :int32_t
213
+ attach_function :ubrk_next, "ubrk_next#{suffix}", [:pointer], :int32_t
214
+ attach_function :ubrk_previous, "ubrk_previous#{suffix}", [:pointer], :int32_t
215
+ attach_function :ubrk_first, "ubrk_first#{suffix}", [:pointer], :int32_t
216
+ attach_function :ubrk_last, "ubrk_last#{suffix}", [:pointer], :int32_t
217
+
218
+ attach_function :ubrk_preceding, "ubrk_preceding#{suffix}", [:pointer, :int32_t], :int32_t
219
+ attach_function :ubrk_following, "ubrk_following#{suffix}", [:pointer, :int32_t], :int32_t
220
+ attach_function :ubrk_isBoundary, "ubrk_isBoundary#{suffix}", [:pointer, :int32_t], :int32_t
217
221
 
218
222
  end # Lib
219
223
  end # ICU
@@ -26,18 +26,18 @@ module ICU
26
26
  class Transliterator
27
27
 
28
28
  def initialize(id, rules = nil, direction = :forward)
29
+ rules_length = 0
30
+
29
31
  if rules
30
32
  rules_length = rules.length + 1
31
33
  rules = UCharPointer.from_string(rules)
32
- else
33
- rules_length = 0
34
34
  end
35
35
 
36
36
  parse_error = Lib::UParseError.new
37
37
  begin
38
38
  Lib.check_error do |status|
39
39
  # couldn't get utrans_openU to work properly, so using deprecated utrans_open for now
40
- @tr = Lib.utrans_open(id, direction, rules, rules_length, @parse_error, status)
40
+ @tr = Lib.utrans_openU(UCharPointer.from_string(id), id.length, direction, rules, rules_length, @parse_error, status)
41
41
  end
42
42
  rescue ICU::Error => ex
43
43
  raise ex, "#{ex.message} (#{parse_error})"
@@ -1,3 +1,3 @@
1
1
  module ICU
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -30,9 +30,9 @@ module ICU
30
30
  ids.should_not be_empty
31
31
  end
32
32
 
33
- # it "should transliterate custom rules" do
34
- # ICU::Transliteration.translit("Accents-Any", "âêîôû", "NFD; [:Nonspacing Mark:] Remove; NFC").should == "aeiou"
35
- # end
33
+ it "should transliterate custom rules" do
34
+ ICU::Transliteration.translit("NFD; [:Nonspacing Mark:] Remove; NFC", "âêîôû").should == "aeiou"
35
+ end
36
36
 
37
37
  end # Transliteration
38
38
  end # ICU
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ffi-icu
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jari Bakken