ffi-icu 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +3 -2
- data/Gemfile +2 -2
- data/LICENSE +1 -1
- data/README.md +6 -6
- data/lib/ffi-icu/collation.rb +8 -0
- data/lib/ffi-icu/lib.rb +1 -0
- data/lib/ffi-icu/transliteration.rb +6 -4
- data/lib/ffi-icu/uchar.rb +13 -2
- data/lib/ffi-icu/version.rb +1 -1
- data/spec/collation_spec.rb +6 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/transliteration_spec.rb +2 -2
- data/spec/uchar_spec.rb +5 -0
- metadata +19 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f2a47f5a65ad78641ecce2ffbbbe66ece2f1f176
|
4
|
+
data.tar.gz: 6b6843b7b398a028e98b1254c22392bfa2ff7394
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70c720e7259427e54f4157f3ed0dafd868547a943a07348bbd91936927b64887b5b23fa73e1a29428a48266c70134e9872c846d2d1a947749cd19a00742aaec7
|
7
|
+
data.tar.gz: 74a4c5a488584a3eee26b880c7af78a308fb4a3fc4d544cc4c3a903f67858e140f90e192bce1bafdfd73929fc4a10ec937b9f79391517962f58985abd46b2dfe
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gemspec
|
3
|
+
gemspec
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -15,13 +15,13 @@ Gem
|
|
15
15
|
Dependencies
|
16
16
|
------------
|
17
17
|
|
18
|
-
ICU.
|
18
|
+
ICU.
|
19
19
|
|
20
20
|
If you get messages that the library or functions are not found, you can
|
21
21
|
set some environment varibles to tell ffi-icu where to find it, e.g.:
|
22
|
-
|
22
|
+
|
23
23
|
$ export FFI_ICU_LIB="icui18n.so"
|
24
|
-
$ export FFI_ICU_VERSION_SUFFIX="_3_8"
|
24
|
+
$ export FFI_ICU_VERSION_SUFFIX="_3_8"
|
25
25
|
$ ruby -r ffi-icu program.rb
|
26
26
|
|
27
27
|
Features
|
@@ -44,7 +44,7 @@ or
|
|
44
44
|
```ruby
|
45
45
|
detector = ICU::CharDet::Detector.new
|
46
46
|
detector.detect(str) => #<struct ICU::CharDet::Detector::Match ...>
|
47
|
-
```
|
47
|
+
```
|
48
48
|
|
49
49
|
Why not just use rchardet?
|
50
50
|
|
@@ -68,7 +68,7 @@ or
|
|
68
68
|
collator.greater?("z", "a") #=> true
|
69
69
|
collator.collate(%w[å æ ø]) #=> ["æ", "ø", "å"]
|
70
70
|
```
|
71
|
-
|
71
|
+
|
72
72
|
Text Boundary Analysis
|
73
73
|
----------------------
|
74
74
|
|
@@ -115,4 +115,4 @@ Note on Patches/Pull Requests
|
|
115
115
|
Copyright
|
116
116
|
=========
|
117
117
|
|
118
|
-
Copyright (c) 2010-
|
118
|
+
Copyright (c) 2010-2014 Jari Bakken. See LICENSE for details.
|
data/lib/ffi-icu/collation.rb
CHANGED
@@ -76,6 +76,14 @@ module ICU
|
|
76
76
|
|
77
77
|
sortable.sort { |a, b| compare a, b }
|
78
78
|
end
|
79
|
+
|
80
|
+
def rules
|
81
|
+
@rules ||= begin
|
82
|
+
length = FFI::MemoryPointer.new(:int)
|
83
|
+
ptr = ICU::Lib.ucol_getRules(@c, length)
|
84
|
+
ptr.read_array_of_uint16(length.read_int).pack("U*")
|
85
|
+
end
|
86
|
+
end
|
79
87
|
end # Collator
|
80
88
|
|
81
89
|
end # Collate
|
data/lib/ffi-icu/lib.rb
CHANGED
@@ -286,6 +286,7 @@ module ICU
|
|
286
286
|
attach_function :ucol_greater, "ucol_greater#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
|
287
287
|
attach_function :ucol_greaterOrEqual, "ucol_greaterOrEqual#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
|
288
288
|
attach_function :ucol_equal, "ucol_equal#{suffix}", [:pointer, :pointer, :int32_t, :pointer, :int32_t], :bool
|
289
|
+
attach_function :ucol_getRules, "ucol_getRules#{suffix}", [:pointer, :pointer], :pointer
|
289
290
|
|
290
291
|
# Transliteration
|
291
292
|
#
|
@@ -33,7 +33,6 @@ module ICU
|
|
33
33
|
parse_error = Lib::UParseError.new
|
34
34
|
begin
|
35
35
|
Lib.check_error do |status|
|
36
|
-
# couldn't get utrans_openU to work properly, so using deprecated utrans_open for now
|
37
36
|
ptr = Lib.utrans_openU(UCharPointer.from_string(id), id.jlength, direction, rules, rules_length, @parse_error, status)
|
38
37
|
@tr = FFI::AutoPointer.new(ptr, Lib.method(:utrans_close))
|
39
38
|
end
|
@@ -69,9 +68,13 @@ module ICU
|
|
69
68
|
raise BufferOverflowError, "needed #{new_size}" if retried
|
70
69
|
|
71
70
|
capacity = new_size + 1
|
72
|
-
buf = buf.resized_to capacity
|
73
|
-
retried = true
|
74
71
|
|
72
|
+
# create a new buffer with more capacity instead of resizing,
|
73
|
+
# since the old buffer now has result data
|
74
|
+
buf.free
|
75
|
+
buf = UCharPointer.from_string(from, capacity)
|
76
|
+
|
77
|
+
retried = true
|
75
78
|
retry
|
76
79
|
end
|
77
80
|
|
@@ -81,4 +84,3 @@ module ICU
|
|
81
84
|
end # Transliterator
|
82
85
|
end # Translit
|
83
86
|
end # ICU
|
84
|
-
|
data/lib/ffi-icu/uchar.rb
CHANGED
@@ -4,11 +4,21 @@ module ICU
|
|
4
4
|
UCHAR_TYPE = :uint16 # not sure how platform-dependent this is..
|
5
5
|
TYPE_SIZE = FFI.type_size(UCHAR_TYPE)
|
6
6
|
|
7
|
-
def self.from_string(str)
|
7
|
+
def self.from_string(str, capacity = nil)
|
8
8
|
str = str.encode("UTF-8") if str.respond_to? :encode
|
9
9
|
bytes = str.unpack("U*")
|
10
10
|
|
11
|
-
|
11
|
+
if capacity
|
12
|
+
capacity *= TYPE_SIZE
|
13
|
+
if capacity < bytes.size
|
14
|
+
raise ArgumentError, "capacity is too small for string of #{bytes.size} bytes"
|
15
|
+
end
|
16
|
+
|
17
|
+
ptr = new capacity
|
18
|
+
else
|
19
|
+
ptr = new bytes.size
|
20
|
+
end
|
21
|
+
|
12
22
|
ptr.write_array_of_uint16 bytes
|
13
23
|
|
14
24
|
ptr
|
@@ -20,6 +30,7 @@ module ICU
|
|
20
30
|
|
21
31
|
def resized_to(new_size)
|
22
32
|
raise "new_size must be larger than current size" if new_size < size
|
33
|
+
|
23
34
|
resized = self.class.new new_size
|
24
35
|
resized.put_bytes(0, get_bytes(0, size))
|
25
36
|
|
data/lib/ffi-icu/version.rb
CHANGED
data/spec/collation_spec.rb
CHANGED
@@ -55,6 +55,12 @@ module ICU
|
|
55
55
|
collator.should_not be_equal("a", "b")
|
56
56
|
end
|
57
57
|
|
58
|
+
it "should return rules" do
|
59
|
+
collator.rules.should_not be_empty
|
60
|
+
# ö sorts before Ö
|
61
|
+
collator.rules.include?('ö<<<Ö').should be_true
|
62
|
+
end
|
63
|
+
|
58
64
|
end
|
59
65
|
end # Collate
|
60
66
|
end # ICU
|
data/spec/spec_helper.rb
CHANGED
@@ -4,14 +4,14 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
module ICU
|
6
6
|
describe Transliteration::Transliterator do
|
7
|
-
|
8
7
|
def transliterator_for(*args)
|
9
8
|
Transliteration::Transliterator.new(*args)
|
10
9
|
end
|
11
10
|
|
12
11
|
[
|
13
12
|
["Any-Hex", "abcde", "\\u0061\\u0062\\u0063\\u0064\\u0065"],
|
14
|
-
["Lower", "ABC", "abc"]
|
13
|
+
["Lower", "ABC", "abc"],
|
14
|
+
["en", "雙屬性集合之空間分群演算法-應用於地理資料", "shuāng shǔ xìng jí hé zhī kōng jiān fēn qún yǎn suàn fǎ-yīng yòng yú de lǐ zī liào"]
|
15
15
|
].each do |id, input, output|
|
16
16
|
it "should transliterate #{id}" do
|
17
17
|
tl = transliterator_for(id)
|
data/spec/uchar_spec.rb
CHANGED
@@ -15,6 +15,11 @@ module ICU
|
|
15
15
|
ptr.read_array_of_uint16(3).should == [0x61, 0x62, 0x63]
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'takes an optional capacity' do
|
19
|
+
ptr = UCharPointer.from_string('abc', 5)
|
20
|
+
ptr.size.should == 20
|
21
|
+
end
|
22
|
+
|
18
23
|
describe 'converting to string' do
|
19
24
|
let(:ptr) { UCharPointer.new(3).write_array_of_uint16 [0x78, 0x0, 0x79] }
|
20
25
|
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-icu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jari Bakken
|
@@ -14,55 +13,49 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: ffi
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.0'
|
22
|
-
- -
|
20
|
+
- - ">="
|
23
21
|
- !ruby/object:Gem::Version
|
24
22
|
version: 1.0.9
|
25
23
|
type: :runtime
|
26
24
|
prerelease: false
|
27
25
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
26
|
requirements:
|
30
|
-
- - ~>
|
27
|
+
- - "~>"
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '1.0'
|
33
|
-
- -
|
30
|
+
- - ">="
|
34
31
|
- !ruby/object:Gem::Version
|
35
32
|
version: 1.0.9
|
36
33
|
- !ruby/object:Gem::Dependency
|
37
34
|
name: rspec
|
38
35
|
requirement: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
36
|
requirements:
|
41
|
-
- - ~>
|
37
|
+
- - "~>"
|
42
38
|
- !ruby/object:Gem::Version
|
43
39
|
version: 2.5.0
|
44
40
|
type: :development
|
45
41
|
prerelease: false
|
46
42
|
version_requirements: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
43
|
requirements:
|
49
|
-
- - ~>
|
44
|
+
- - "~>"
|
50
45
|
- !ruby/object:Gem::Version
|
51
46
|
version: 2.5.0
|
52
47
|
- !ruby/object:Gem::Dependency
|
53
48
|
name: rake
|
54
49
|
requirement: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
50
|
requirements:
|
57
|
-
- - ~>
|
51
|
+
- - "~>"
|
58
52
|
- !ruby/object:Gem::Version
|
59
53
|
version: 0.9.2
|
60
54
|
type: :development
|
61
55
|
prerelease: false
|
62
56
|
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
57
|
requirements:
|
65
|
-
- - ~>
|
58
|
+
- - "~>"
|
66
59
|
- !ruby/object:Gem::Version
|
67
60
|
version: 0.9.2
|
68
61
|
description: Provides charset detection, locale sensitive collation and more. Depends
|
@@ -74,9 +67,9 @@ extra_rdoc_files:
|
|
74
67
|
- LICENSE
|
75
68
|
- README.md
|
76
69
|
files:
|
77
|
-
- .document
|
78
|
-
- .gitignore
|
79
|
-
- .travis.yml
|
70
|
+
- ".document"
|
71
|
+
- ".gitignore"
|
72
|
+
- ".travis.yml"
|
80
73
|
- Gemfile
|
81
74
|
- LICENSE
|
82
75
|
- README.md
|
@@ -110,31 +103,27 @@ files:
|
|
110
103
|
- test.c
|
111
104
|
homepage: http://github.com/jarib/ffi-icu
|
112
105
|
licenses: []
|
106
|
+
metadata: {}
|
113
107
|
post_install_message:
|
114
108
|
rdoc_options:
|
115
|
-
- --charset=UTF-8
|
109
|
+
- "--charset=UTF-8"
|
116
110
|
require_paths:
|
117
111
|
- lib
|
118
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
113
|
requirements:
|
121
|
-
- -
|
114
|
+
- - ">="
|
122
115
|
- !ruby/object:Gem::Version
|
123
116
|
version: '0'
|
124
|
-
segments:
|
125
|
-
- 0
|
126
|
-
hash: 2331794964690554851
|
127
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
-
none: false
|
129
118
|
requirements:
|
130
|
-
- -
|
119
|
+
- - ">="
|
131
120
|
- !ruby/object:Gem::Version
|
132
121
|
version: '0'
|
133
122
|
requirements: []
|
134
123
|
rubyforge_project:
|
135
|
-
rubygems_version:
|
124
|
+
rubygems_version: 2.2.0
|
136
125
|
signing_key:
|
137
|
-
specification_version:
|
126
|
+
specification_version: 4
|
138
127
|
summary: Simple Ruby FFI wrappers for things I need from ICU.
|
139
128
|
test_files:
|
140
129
|
- spec/break_iterator_spec.rb
|
@@ -148,3 +137,4 @@ test_files:
|
|
148
137
|
- spec/spec_helper.rb
|
149
138
|
- spec/transliteration_spec.rb
|
150
139
|
- spec/uchar_spec.rb
|
140
|
+
has_rdoc:
|