ffi-icu 0.4.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2066f9d1a113f07fb761d2c97f742e6cad8dde11b26c0e4d1da2ed8a85567297
4
- data.tar.gz: e6df31c42fc3e518d8d19a98dec0b5aeed37ae90da3fd7570f32ef58397d531d
3
+ metadata.gz: 448bbb49f51d0f81ab1aba8425c9c814fa9bb2ca06317022f1bc703769d87838
4
+ data.tar.gz: 27331bf11c467dc52c4ddb4bfbee954d7b0682dbeb90e802482631640e0db0fb
5
5
  SHA512:
6
- metadata.gz: bf39178c2893939c57a8e7810d407da635ceff9b4cc5ddbe60360df53a0bf7f35b17d8f4036cf001d85edf4fa83efd8f4ed1b91d6cdb21e54d52810f536bf7ce
7
- data.tar.gz: ee8c887487e3c3a0c0511e7017753b4801da3fc6a73e4d476211452026fd0ae3d8ae0d4c35be9eb5ed8827df8b757bc985dc5f5eafc77a12c872ca37347e9924
6
+ metadata.gz: d6d001728de2428460f163248ed9394680e9ca5509aa0644b9290de294993637ff982ec0fe7e87f40f3f1fba4a6b9dfe542147ed9a699588aae9aa80b5d01c59
7
+ data.tar.gz: 3c9fa41df884315d1d4a9e726b4d55c20d1d962c6e9abce260a9ab68a9ae12cb4ba0c7a8fb0f04628b9e9497c41594a5394a994f2b154aad4da1d177f4997abd
data/lib/ffi-icu/lib.rb CHANGED
@@ -19,9 +19,7 @@ module ICU
19
19
  '/usr/local/{lib64,lib}',
20
20
  '/opt/local/{lib64,lib}',
21
21
  '/usr/{lib64,lib}',
22
- '/usr/lib/x86_64-linux-gnu', # for Debian Multiarch http://wiki.debian.org/Multiarch
23
- '/usr/lib/i386-linux-gnu', # for Debian Multiarch
24
- ]
22
+ ] + Dir['/usr/lib/*-linux-gnu'] # for Debian Multiarch http://wiki.debian.org/Multiarch
25
23
  end
26
24
  end
27
25
  end
@@ -68,8 +68,19 @@ module ICU
68
68
  case number
69
69
  when Float
70
70
  needed_length = Lib.unum_format_double(@f, number, out_ptr, needed_length, nil, error)
71
- when Fixnum
72
- needed_length = Lib.unum_format_int32(@f, number, out_ptr, needed_length, nil, error)
71
+ when Integer
72
+ begin
73
+ # Try doing it fast, for integers that can be marshaled into an int64_t
74
+ needed_length = Lib.unum_format_int64(@f, number, out_ptr, needed_length, nil, error)
75
+ rescue RangeError
76
+ # Fall back to stringifying in Ruby and passing that to ICU
77
+ unless defined? Lib.unum_format_decimal
78
+ raise RangeError,"Number #{number} is too big to fit in int64_t and your "\
79
+ "ICU version is too old to have unum_format_decimal"
80
+ end
81
+ string_version = number.to_s
82
+ needed_length = Lib.unum_format_decimal(@f, string_version, string_version.bytesize, out_ptr, needed_length, nil, error)
83
+ end
73
84
  when BigDecimal
74
85
  string_version = number.to_s('F')
75
86
  if Lib.respond_to? :unum_format_decimal
@@ -77,8 +88,6 @@ module ICU
77
88
  else
78
89
  needed_length = Lib.unum_format_double(@f, number.to_f, out_ptr, needed_length, nil, error)
79
90
  end
80
- when Bignum
81
- needed_length = Lib.unum_format_int64(@f, number, out_ptr, needed_length, nil, error)
82
91
  end
83
92
  end
84
93
  out_ptr.string needed_length
@@ -115,7 +115,7 @@ module ICU
115
115
 
116
116
  def parse(str)
117
117
  str_u = UCharPointer.from_string(str)
118
- str_l = str_u.size
118
+ str_l = str.size
119
119
  Lib.check_error do |error|
120
120
  ret = Lib.udat_parse(@f, str_u, str_l, nil, error)
121
121
  Time.at(ret / 1000.0)
@@ -190,8 +190,9 @@ module ICU
190
190
  end
191
191
  end
192
192
 
193
- def skeleton_format(pattern, locale)
194
- pattern = UCharPointer.from_string(pattern)
193
+ def skeleton_format(skeleton_pattern_str, locale)
194
+ skeleton_pattern_ptr = UCharPointer.from_string(skeleton_pattern_str)
195
+ skeleton_pattern_len = skeleton_pattern_str.size
195
196
 
196
197
  needed_length = 0
197
198
  pattern_ptr = UCharPointer.new(needed_length)
@@ -203,7 +204,7 @@ module ICU
203
204
 
204
205
  begin
205
206
  Lib.check_error do |error|
206
- needed_length = Lib.udatpg_getBestPattern(generator, pattern, pattern.size, pattern_ptr, needed_length, error)
207
+ needed_length = Lib.udatpg_getBestPattern(generator, skeleton_pattern_ptr, skeleton_pattern_len, pattern_ptr, needed_length, error)
207
208
  end
208
209
 
209
210
  return needed_length, pattern_ptr
@@ -1,3 +1,3 @@
1
1
  module ICU
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -69,6 +69,11 @@ module ICU
69
69
  expect { NumberFormatting.create('en-US', :currency, style: :iso) }.to raise_error(StandardError)
70
70
  end
71
71
  end
72
+
73
+ it 'should format a bignum' do
74
+ str = NumberFormatting.format_number("en", 1_000_000_000_000_000_000_000_000_000_000_000_000_000)
75
+ expect(str).to eq('1,000,000,000,000,000,000,000,000,000,000,000,000,000')
76
+ end
72
77
  end
73
78
  end # NumberFormatting
74
79
  end # ICU
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken