ffi-icu 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ffi-icu/lib.rb +1 -3
- data/lib/ffi-icu/number_formatting.rb +13 -4
- data/lib/ffi-icu/time_formatting.rb +5 -4
- data/lib/ffi-icu/version.rb +1 -1
- data/spec/number_formatting_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 448bbb49f51d0f81ab1aba8425c9c814fa9bb2ca06317022f1bc703769d87838
|
4
|
+
data.tar.gz: 27331bf11c467dc52c4ddb4bfbee954d7b0682dbeb90e802482631640e0db0fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
72
|
-
|
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 =
|
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(
|
194
|
-
|
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,
|
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
|
data/lib/ffi-icu/version.rb
CHANGED
@@ -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
|