ffi-icu 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -3,4 +3,4 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  before_script:
6
- - sudo apt-get install -y libicu44
6
+ - sudo apt-get install -y libicu48
data/lib/ffi-icu/lib.rb CHANGED
@@ -129,14 +129,6 @@ module ICU
129
129
  ret
130
130
  end
131
131
 
132
- def self.cldr_version
133
- result = FFI::MemoryPointer.new(:char, 64)
134
- version_info = FFI::MemoryPointer.new(:uint8, 4)
135
- check_error { |status| ulocdata_getCLDRVersion(version_info, status) }
136
- u_versionToString(version_info, result)
137
- result.read_string_to_null
138
- end
139
-
140
132
  def self.enum_ptr_to_array(enum_ptr)
141
133
  length = check_error do |status|
142
134
  uenum_count(enum_ptr, status)
@@ -155,16 +147,55 @@ module ICU
155
147
  end
156
148
  end
157
149
 
150
+ class VersionInfo < FFI::MemoryPointer
151
+ extend FFI::DataConverter
152
+
153
+ MaxLength = 4
154
+ MaxStringLength = 20
155
+
156
+ def self.native_type
157
+ FFI::Type::POINTER
158
+ end
159
+
160
+ def initialize
161
+ super :uint8, MaxLength
162
+ end
163
+
164
+ def to_a
165
+ read_array_of_uint8(MaxLength)
166
+ end
167
+
168
+ def to_s
169
+ buffer = FFI::MemoryPointer.new(:char, MaxStringLength)
170
+ Lib.u_versionToString(self, buffer)
171
+ buffer.read_string_to_null
172
+ end
173
+ end
174
+
175
+ def self.cldr_version
176
+ @cldr_version ||= VersionInfo.new.tap do |version|
177
+ check_error { |status| ulocdata_getCLDRVersion(version, status) }
178
+ end
179
+ end
180
+
181
+ def self.version
182
+ @version ||= VersionInfo.new.tap { |version| u_getVersion(version) }
183
+ end
184
+
158
185
  version = load_icu
159
186
  suffix = figure_suffix(version)
160
187
 
188
+ typedef VersionInfo, :version
189
+
161
190
  attach_function :u_errorName, "u_errorName#{suffix}", [:int], :string
162
191
  attach_function :uenum_count, "uenum_count#{suffix}", [:pointer, :pointer], :int
163
192
  attach_function :uenum_close, "uenum_close#{suffix}", [:pointer], :void
164
193
  attach_function :uenum_next, "uenum_next#{suffix}", [:pointer, :pointer, :pointer], :string
165
194
  attach_function :u_charsToUChars, "u_charsToUChars#{suffix}", [:string, :pointer, :int32_t], :void
166
195
  attach_function :u_UCharsToChars, "u_UCharsToChars#{suffix}", [:pointer, :string, :int32_t], :void
167
- attach_function :u_versionToString, "u_versionToString#{suffix}", [:pointer, :pointer], :void
196
+
197
+ attach_function :u_getVersion, "u_getVersion#{suffix}", [:version], :void
198
+ attach_function :u_versionToString, "u_versionToString#{suffix}", [:version, :pointer], :void
168
199
 
169
200
  #
170
201
  # Locale
@@ -174,10 +205,8 @@ module ICU
174
205
 
175
206
  enum :layout_type, [:ltr, :rtl, :ttb, :btt, :unknown]
176
207
 
177
- attach_function :uloc_addLikelySubtags, "uloc_addLikelySubtags#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
178
208
  attach_function :uloc_canonicalize, "uloc_canonicalize#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
179
209
  attach_function :uloc_countAvailable, "uloc_countAvailable#{suffix}", [], :int32_t
180
- attach_function :uloc_forLanguageTag, "uloc_forLanguageTag#{suffix}", [:string, :pointer, :int32_t, :pointer, :pointer], :int32_t
181
210
  attach_function :uloc_getAvailable, "uloc_getAvailable#{suffix}", [:int32_t], :string
182
211
  attach_function :uloc_getBaseName, "uloc_getBaseName#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
183
212
  attach_function :uloc_getCountry, "uloc_getCountry#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
@@ -188,19 +217,15 @@ module ICU
188
217
  attach_function :uloc_getISOLanguages, "uloc_getISOLanguages#{suffix}", [], :pointer
189
218
  attach_function :uloc_getKeywordValue, "uloc_getKeywordValue#{suffix}", [:string, :string, :pointer, :int32_t, :pointer], :int32_t
190
219
  attach_function :uloc_getLanguage, "uloc_getLanguage#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
191
- attach_function :uloc_getLocaleForLCID, "uloc_getLocaleForLCID#{suffix}", [:uint32, :pointer, :int32_t, :pointer], :int32_t
192
220
  attach_function :uloc_getLCID, "uloc_getLCID#{suffix}", [:string], :uint32
193
221
  attach_function :uloc_getName, "uloc_getName#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
194
222
  attach_function :uloc_getParent, "uloc_getParent#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
195
223
  attach_function :uloc_getScript, "uloc_getScript#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
196
224
  attach_function :uloc_getVariant, "uloc_getVariant#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
197
- attach_function :uloc_minimizeSubtags, "uloc_minimizeSubtags#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
198
225
  attach_function :uloc_openKeywords, "uloc_openKeywords#{suffix}", [:string, :pointer], :pointer
199
226
  attach_function :uloc_setDefault, "uloc_setDefault#{suffix}", [:string, :pointer], :void
200
227
  attach_function :uloc_setKeywordValue, "uloc_setKeywordValue#{suffix}", [:string, :string, :pointer, :int32_t, :pointer], :int32_t
201
- attach_function :uloc_toLanguageTag, "uloc_toLanguageTag#{suffix}", [:string, :pointer, :int32_t, :int8_t, :pointer], :int32_t
202
228
 
203
- attach_function :uloc_getCharacterOrientation, "uloc_getCharacterOrientation#{suffix}", [:string, :pointer], :layout_type
204
229
  attach_function :uloc_getDisplayCountry, "uloc_getDisplayCountry#{suffix}", [:string, :string, :pointer, :int32_t, :pointer], :int32_t
205
230
  attach_function :uloc_getDisplayKeyword, "uloc_getDisplayKeyword#{suffix}", [:string, :string, :pointer, :int32_t, :pointer], :int32_t
206
231
  attach_function :uloc_getDisplayKeywordValue, "uloc_getDisplayKeywordValue#{suffix}", [:string, :string, :string, :pointer, :int32_t, :pointer], :int32_t
@@ -208,9 +233,24 @@ module ICU
208
233
  attach_function :uloc_getDisplayName, "uloc_getDisplayName#{suffix}", [:string, :string, :pointer, :int32_t, :pointer], :int32_t
209
234
  attach_function :uloc_getDisplayScript, "uloc_getDisplayScript#{suffix}", [:string, :string, :pointer, :int32_t, :pointer], :int32_t
210
235
  attach_function :uloc_getDisplayVariant, "uloc_getDisplayVariant#{suffix}", [:string, :string, :pointer, :int32_t, :pointer], :int32_t
211
- attach_function :uloc_getLineOrientation, "uloc_getLineOrientation#{suffix}", [:string, :pointer], :layout_type
212
236
 
213
- attach_function :ulocdata_getCLDRVersion, "ulocdata_getCLDRVersion#{suffix}", [:pointer, :pointer], :void
237
+ if Gem::Version.new('3.8') <= Gem::Version.new(self.version)
238
+ attach_function :uloc_getLocaleForLCID, "uloc_getLocaleForLCID#{suffix}", [:uint32, :pointer, :int32_t, :pointer], :int32_t
239
+ end
240
+
241
+ if Gem::Version.new('4.0') <= Gem::Version.new(self.version)
242
+ attach_function :uloc_addLikelySubtags, "uloc_addLikelySubtags#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
243
+ attach_function :uloc_minimizeSubtags, "uloc_minimizeSubtags#{suffix}", [:string, :pointer, :int32_t, :pointer], :int32_t
244
+ attach_function :uloc_getCharacterOrientation, "uloc_getCharacterOrientation#{suffix}", [:string, :pointer], :layout_type
245
+ attach_function :uloc_getLineOrientation, "uloc_getLineOrientation#{suffix}", [:string, :pointer], :layout_type
246
+ end
247
+
248
+ if Gem::Version.new('4.2') <= Gem::Version.new(self.version)
249
+ attach_function :uloc_forLanguageTag, "uloc_forLanguageTag#{suffix}", [:string, :pointer, :int32_t, :pointer, :pointer], :int32_t
250
+ attach_function :uloc_toLanguageTag, "uloc_toLanguageTag#{suffix}", [:string, :pointer, :int32_t, :int8_t, :pointer], :int32_t
251
+
252
+ attach_function :ulocdata_getCLDRVersion, "ulocdata_getCLDRVersion#{suffix}", [:version, :pointer], :void
253
+ end
214
254
 
215
255
  # CharDet
216
256
  #
@@ -5,7 +5,7 @@ module ICU
5
5
  offset = 0
6
6
  result = []
7
7
 
8
- while (ptr = pointer.get_pointer(offset)) != FFI::Pointer::NULL do
8
+ until (ptr = pointer.get_pointer(offset)).null?
9
9
  result << ptr.read_string
10
10
  offset += FFI::Pointer.size
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module ICU
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module ICU
6
+ module Lib
7
+ describe VersionInfo do
8
+ its(:to_a) { should be_an Array }
9
+ its(:to_s) do
10
+ should be_a String
11
+ should match /^[0-9.]+$/
12
+ end
13
+ end
14
+ end
15
+ end
data/spec/lib_spec.rb CHANGED
@@ -43,5 +43,21 @@ module ICU
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ if Gem::Version.new('4.2') <= Gem::Version.new(Lib.version)
48
+ describe 'CLDR version' do
49
+ subject { Lib.cldr_version }
50
+
51
+ it { should be_a Lib::VersionInfo }
52
+ it('is populated') { subject.to_a.should_not == [0,0,0,0] }
53
+ end
54
+ end
55
+
56
+ describe 'ICU version' do
57
+ subject { Lib.version }
58
+
59
+ it { should be_a Lib::VersionInfo }
60
+ it('is populated') { subject.to_a.should_not == [0,0,0,0] }
61
+ end
46
62
  end
47
63
  end
data/spec/locale_spec.rb CHANGED
@@ -59,21 +59,23 @@ module ICU
59
59
  end
60
60
  end
61
61
 
62
- describe 'BCP 47 language tags' do
63
- it 'converts a language tag to a locale' do
64
- Locale.for_language_tag('en-us').should == Locale.new('en_US')
65
- Locale.for_language_tag('nan-Hant-tw').should == Locale.new('nan_Hant_TW')
66
- end
62
+ if Gem::Version.new('4.2') <= Gem::Version.new(Lib.version)
63
+ describe 'BCP 47 language tags' do
64
+ it 'converts a language tag to a locale' do
65
+ Locale.for_language_tag('en-us').should == Locale.new('en_US')
66
+ Locale.for_language_tag('nan-Hant-tw').should == Locale.new('nan_Hant_TW')
67
+ end
67
68
 
68
- it 'returns a language tag for a locale' do
69
- if Gem::Version.new(Lib.cldr_version) < Gem::Version.new('1.8')
70
- Locale.new('en_US').to_language_tag.should == 'en-us'
71
- Locale.new('zh_TW').to_language_tag.should == 'zh-tw'
72
- Locale.new('zh_Hans_CH_PINYIN').to_language_tag.should == 'zh-hans-ch-u-co-pinyin'
73
- else
74
- Locale.new('en_US').to_language_tag.should == 'en-US'
75
- Locale.new('zh_TW').to_language_tag.should == 'zh-TW'
76
- Locale.new('zh_Hans_CH_PINYIN').to_language_tag.should == 'zh-Hans-CH-u-co-pinyin'
69
+ it 'returns a language tag for a locale' do
70
+ if Gem::Version.new('4.4') <= Gem::Version.new(Lib.version)
71
+ Locale.new('en_US').to_language_tag.should == 'en-US'
72
+ Locale.new('zh_TW').to_language_tag.should == 'zh-TW'
73
+ Locale.new('zh_Hans_CH_PINYIN').to_language_tag.should == 'zh-Hans-CH-u-co-pinyin'
74
+ else
75
+ Locale.new('en_US').to_language_tag.should == 'en-us'
76
+ Locale.new('zh_TW').to_language_tag.should == 'zh-tw'
77
+ Locale.new('zh_Hans_CH_PINYIN').to_language_tag.should == 'zh-hans-ch-u-co-pinyin'
78
+ end
77
79
  end
78
80
  end
79
81
  end
@@ -113,11 +115,8 @@ module ICU
113
115
  end
114
116
 
115
117
  it 'returns the variant' do
116
- Locale.new('zh_Hans_CH_PINYIN').display_variant('en').should == 'Pinyin Romanization'
117
-
118
- if Gem::Version.new(Lib.cldr_version) > Gem::Version.new('1.8')
119
- Locale.new('zh_Hans_CH_PINYIN').display_variant('es').should == 'Romanización pinyin'
120
- end
118
+ Locale.new('be_BY_TARASK').display_variant('de').should == 'Taraskievica-Orthographie'
119
+ Locale.new('zh_CH_POSIX').display_variant('en').should == 'Computer'
121
120
  end
122
121
  end
123
122
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-icu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -93,6 +93,7 @@ files:
93
93
  - spec/break_iterator_spec.rb
94
94
  - spec/chardet_spec.rb
95
95
  - spec/collation_spec.rb
96
+ - spec/lib/version_info_spec.rb
96
97
  - spec/lib_spec.rb
97
98
  - spec/locale_spec.rb
98
99
  - spec/normalization_spec.rb
@@ -130,6 +131,7 @@ test_files:
130
131
  - spec/break_iterator_spec.rb
131
132
  - spec/chardet_spec.rb
132
133
  - spec/collation_spec.rb
134
+ - spec/lib/version_info_spec.rb
133
135
  - spec/lib_spec.rb
134
136
  - spec/locale_spec.rb
135
137
  - spec/normalization_spec.rb