ffi-icu 0.0.7 → 0.0.8

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 ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ before_script:
6
+ - sudo apt-get install -y libicu44
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Jari Bakken
1
+ Copyright (c) 2010-2012 Jari Bakken
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -3,6 +3,8 @@ ffi-icu
3
3
 
4
4
  Simple FFI wrappers for things I need from ICU. For the full thing, check out [ICU4R](http://icu4r.rubyforge.org/) instead.
5
5
 
6
+ [![Build Status](https://secure.travis-ci.org/jarib/ffi-icu.png)](http://travis-ci.org/jarib/ffi-icu)
7
+
6
8
  Gem
7
9
  ---
8
10
 
@@ -113,4 +115,4 @@ Note on Patches/Pull Requests
113
115
  Copyright
114
116
  =========
115
117
 
116
- Copyright (c) 2010-2011 Jari Bakken. See LICENSE for details.
118
+ Copyright (c) 2010-2012 Jari Bakken. See LICENSE for details.
data/Rakefile CHANGED
@@ -14,14 +14,12 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
14
14
  spec.rcov = true
15
15
  end
16
16
 
17
- task :spec
18
-
19
17
  task :default => :spec
20
18
 
21
19
  begin
22
20
  require 'yard'
23
21
  YARD::Rake::YardocTask.new
24
- rescue
22
+ rescue LoadError
25
23
  task :yardoc do
26
24
  abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
27
25
  end
data/ffi-icu.gemspec CHANGED
@@ -1,8 +1,3 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
1
  require File.expand_path("../lib/ffi-icu/version", __FILE__)
7
2
 
8
3
  Gem::Specification.new do |s|
@@ -24,7 +19,8 @@ Gem::Specification.new do |s|
24
19
  s.rdoc_options = ["--charset=UTF-8"]
25
20
  s.summary = %q{Simple Ruby FFI wrappers for things I need from ICU.}
26
21
 
27
- s.add_runtime_dependency(%q<ffi>, ["~> 1.0.9"])
28
- s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
22
+ s.add_runtime_dependency "ffi", ["~> 1.0.9"]
23
+ s.add_development_dependency "rspec", ["~> 2.5.0"]
24
+ s.add_development_dependency "rake", ["~> 0.9.2"]
29
25
  end
30
26
 
data/lib/ffi-icu.rb CHANGED
@@ -10,6 +10,8 @@ module ICU
10
10
  :osx
11
11
  when /linux/
12
12
  :linux
13
+ when /bsd/
14
+ :bsd
13
15
  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
14
16
  :windows
15
17
  else
data/lib/ffi-icu/lib.rb CHANGED
@@ -8,60 +8,69 @@ module ICU
8
8
  module Lib
9
9
  extend FFI::Library
10
10
 
11
- VERSIONS = {
12
- "48" => "_48",
13
- "46" => "_46",
14
- "45" => "_45",
15
- "44" => "_44",
16
- "42" => "_4_2",
17
- }
18
-
19
- # FIXME: this is incredibly ugly, figure out some better way
20
- def self.find_icu
21
- suffix = ''
22
-
23
- # let the user tell us where the lib is
24
- if ENV['FFI_ICU_LIB']
25
- libs = ENV['FFI_ICU_LIB'].split(",")
26
- ffi_lib(*libs)
27
-
28
- if ENV['FFI_ICU_VERSION_SUFFIX']
29
- return ENV['FFI_ICU_VERSION_SUFFIX']
30
- elsif num = libs.first[/\d+$/]
31
- return num.split(//).join("_")
11
+ def self.search_paths
12
+ @search_paths ||= begin
13
+ if ENV['FFI_ICU_LIB']
14
+ [ ENV['FFI_ICU_LIB'] ]
15
+ elsif FFI::Platform::IS_WINDOWS
16
+ ENV['PATH'].split(File::PATH_SEPARATOR)
32
17
  else
33
- return suffix
18
+ [ '/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}' ]
34
19
  end
35
20
  end
21
+ end
22
+
23
+ def self.find_lib(lib)
24
+ Dir.glob(search_paths.map { |path|
25
+ File.expand_path(File.join(path, lib))
26
+ }).first
27
+ end
36
28
 
37
- libs = nil
38
- versions = VERSIONS.keys
39
-
40
- # ok, try to find it
41
- case ICU.platform
42
- when :osx
43
- ffi_lib "icucore"
44
- when :linux
45
- libs = ffi_lib versions.map { |v| "libicui18n.so.#{v}" },
46
- versions.map { |v| "libicutu.so.#{v}" }
47
-
48
- when :windows
49
- libs = ffi_lib versions.map { |v| "icuin#{v}.dll" }
50
- else
51
- raise LoadError
29
+ def self.load_icu
30
+ # First find the library
31
+ lib_names = case ICU.platform
32
+ when :osx
33
+ [find_lib("libicucore.#{FFI::Platform::LIBSUFFIX}")]
34
+ when :linux
35
+ [find_lib("libicui18n.#{FFI::Platform::LIBSUFFIX}.??"),
36
+ find_lib("libicutu.#{FFI::Platform::LIBSUFFIX}.??")]
37
+ when :windows
38
+ [find_lib("icuuc??.#{FFI::Platform::LIBSUFFIX}"),
39
+ find_lib("icuin??.#{FFI::Platform::LIBSUFFIX}")]
40
+ end
41
+
42
+ lib_names.compact! if lib_names
43
+
44
+ if not lib_names or lib_names.length == 0
45
+ raise LoadError, "Could not find ICU on #{ICU.platform.inspect}, patches appreciated!"
52
46
  end
53
47
 
54
- if libs
55
- lib_name = libs.first.name
56
- version = VERSIONS.find { |object, func| lib_name =~ /#{object}(\.dll)?$/ }
48
+ # And now try to load the library
49
+ begin
50
+ libs = ffi_lib(*lib_names)
51
+ rescue LoadError => ex
52
+ raise LoadError, "no idea how to load ICU on #{ICU.platform.inspect}, patches appreciated! (#{ex.message})"
53
+ end
57
54
 
58
- version or raise "unable to find suffix in #{lib_name}"
59
- suffix = version.last
55
+ # And last figure out the version we just loaded
56
+ icu_version(libs)
57
+ end
58
+
59
+ def self.icu_version(libs)
60
+ version = nil
61
+
62
+ libs.find do |lib|
63
+ # Get the version - sure would be nice if libicu exported this in a function
64
+ # we could just call cause this is super fugly!
65
+ match = lib.name.match(/(\d\d)\.#{FFI::Platform::LIBSUFFIX}/) ||
66
+ lib.name.match(/#{FFI::Platform::LIBSUFFIX}\.(\d\d)/)
67
+ if match
68
+ version = match[1]
69
+ end
60
70
  end
61
71
 
62
- suffix
63
- rescue LoadError => ex
64
- raise LoadError, "no idea how to load ICU on #{ICU.platform.inspect}, patches appreciated! (#{ex.message})"
72
+ # Note this may return nil, like on OSX
73
+ version
65
74
  end
66
75
 
67
76
  def self.check_error
@@ -101,8 +110,8 @@ module ICU
101
110
  end
102
111
  end
103
112
 
104
-
105
- suffix = find_icu()
113
+ version = load_icu
114
+ suffix = version ? "_#{version}" : ""
106
115
 
107
116
  attach_function :u_errorName, "u_errorName#{suffix}", [:int], :string
108
117
  attach_function :uenum_count, "uenum_count#{suffix}", [:pointer, :pointer], :int
@@ -190,7 +199,7 @@ module ICU
190
199
  :default, 4,
191
200
  :nfkc, 5,
192
201
  :fcd, 6
193
- ]
202
+ ]
194
203
 
195
204
  attach_function :unorm_normalize, "unorm_normalize#{suffix}", [:pointer, :int32_t, :normalization_mode, :int32_t, :pointer, :int32_t, :pointer], :int32_t
196
205
 
@@ -211,7 +220,7 @@ module ICU
211
220
  :kana_limit, 400,
212
221
  :ideo, 400,
213
222
  :ideo_limit, 400
214
- ]
223
+ ]
215
224
 
216
225
  attach_function :ubrk_countAvailable, "ubrk_countAvailable#{suffix}", [], :int32_t
217
226
  attach_function :ubrk_getAvailable, "ubrk_getAvailable#{suffix}", [:int32_t], :string
@@ -1,3 +1,3 @@
1
1
  module ICU
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/spec/chardet_spec.rb CHANGED
@@ -4,16 +4,16 @@ require 'spec_helper'
4
4
 
5
5
  describe ICU::CharDet::Detector do
6
6
 
7
- before { @d = ICU::CharDet::Detector.new }
7
+ let(:detector) { ICU::CharDet::Detector.new }
8
8
 
9
9
  it "should recognize UTF-8" do
10
- m = @d.detect("æåø")
10
+ m = detector.detect("æåø")
11
11
  m.name.should == "UTF-8"
12
12
  m.language.should be_kind_of(String)
13
13
  end
14
14
 
15
15
  it "has a list of detectable charsets" do
16
- cs = @d.detectable_charsets
16
+ cs = detector.detectable_charsets
17
17
  cs.should be_kind_of(Array)
18
18
  cs.should_not be_empty
19
19
 
@@ -21,18 +21,17 @@ describe ICU::CharDet::Detector do
21
21
  end
22
22
 
23
23
  it "should disable / enable the input filter" do
24
- @d.input_filter_enabled?.should be_false
25
- @d.input_filter_enabled = true
26
- @d.input_filter_enabled?.should be_true
24
+ detector.input_filter_enabled?.should be_false
25
+ detector.input_filter_enabled = true
26
+ detector.input_filter_enabled?.should be_true
27
27
  end
28
28
 
29
29
  it "should should set declared encoding" do
30
- @d.declared_encoding = "UTF-8"
30
+ detector.declared_encoding = "UTF-8"
31
31
  end
32
32
 
33
33
  it "should detect several matching encodings" do
34
- r = @d.detect_all("foo bar")
35
- r.should be_instance_of(Array)
34
+ detector.detect_all("foo bar").should be_instance_of(Array)
36
35
  end
37
36
 
38
37
  end
@@ -11,15 +11,14 @@ module ICU
11
11
  end
12
12
 
13
13
  describe Collator do
14
-
15
- before { @c = Collator.new("nb") }
14
+ let(:collator) { Collator.new("nb") }
16
15
 
17
16
  it "should collate an array of strings" do
18
- @c.collate(%w[å ø æ]).should == %w[æ ø å]
17
+ collator.collate(%w[å ø æ]).should == %w[æ ø å]
19
18
  end
20
19
 
21
20
  it "raises an error if argument does not respond to :sort" do
22
- lambda { @c.collate(1) }.should raise_error(ArgumentError)
21
+ lambda { collator.collate(1) }.should raise_error(ArgumentError)
23
22
  end
24
23
 
25
24
  it "should return available locales" do
@@ -30,30 +29,30 @@ module ICU
30
29
  end
31
30
 
32
31
  it "should return the locale of the collator" do
33
- l = @c.locale
32
+ l = collator.locale
34
33
  l.should == "nb"
35
34
  end
36
35
 
37
36
  it "should compare two strings" do
38
- @c.compare("blåbærsyltetøy", "blah").should == 1
39
- @c.compare("blah", "blah").should == 0
40
- @c.compare("baah", "blah").should == -1
37
+ collator.compare("blåbærsyltetøy", "blah").should == 1
38
+ collator.compare("blah", "blah").should == 0
39
+ collator.compare("baah", "blah").should == -1
41
40
  end
42
41
 
43
42
  it "should know if a string is greater than another" do
44
- @c.should be_greater("z", "a")
45
- @c.should_not be_greater("a", "z")
43
+ collator.should be_greater("z", "a")
44
+ collator.should_not be_greater("a", "z")
46
45
  end
47
46
 
48
47
  it "should know if a string is greater or equal to another" do
49
- @c.should be_greater_or_equal("z", "a")
50
- @c.should be_greater_or_equal("z", "z")
51
- @c.should_not be_greater_or_equal("a", "z")
48
+ collator.should be_greater_or_equal("z", "a")
49
+ collator.should be_greater_or_equal("z", "z")
50
+ collator.should_not be_greater_or_equal("a", "z")
52
51
  end
53
52
 
54
53
  it "should know if a string is equal to another" do
55
- @c.should be_equal("a", "a")
56
- @c.should_not be_equal("a", "b")
54
+ collator.should be_equal("a", "a")
55
+ collator.should_not be_equal("a", "b")
57
56
  end
58
57
 
59
58
  end
@@ -5,17 +5,17 @@ require "spec_helper"
5
5
  module ICU
6
6
  describe Transliteration::Transliterator do
7
7
 
8
- def transliterator(*args)
9
- @t = Transliteration::Transliterator.new(*args)
8
+ def transliterator_for(*args)
9
+ Transliteration::Transliterator.new(*args)
10
10
  end
11
11
 
12
12
  [
13
- { :id => "Any-Hex", :input => "abcde", :output => "\\u0061\\u0062\\u0063\\u0064\\u0065" },
14
- { :id => "Lower", :input => "ABC", :output => "abc" },
15
- ].each do |test|
16
-
17
- it "should transliterate #{test[:id]}" do
18
- transliterator(test[:id]).transliterate(test[:input]).should == test[:output]
13
+ ["Any-Hex", "abcde", "\\u0061\\u0062\\u0063\\u0064\\u0065"],
14
+ ["Lower", "ABC", "abc"]
15
+ ].each do |id, input, output|
16
+ it "should transliterate #{id}" do
17
+ tl = transliterator_for(id)
18
+ tl.transliterate(input).should == output
19
19
  end
20
20
 
21
21
  end
metadata CHANGED
@@ -1,51 +1,76 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ffi-icu
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
4
5
  prerelease:
5
- version: 0.0.7
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Jari Bakken
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2010-08-23 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2010-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: ffi
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
23
21
  version: 1.0.9
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.9
30
+ - !ruby/object:Gem::Dependency
27
31
  name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.5.0
38
+ type: :development
28
39
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
30
41
  none: false
31
- requirements:
42
+ requirements:
32
43
  - - ~>
33
- - !ruby/object:Gem::Version
44
+ - !ruby/object:Gem::Version
34
45
  version: 2.5.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.2
35
54
  type: :development
36
- version_requirements: *id002
37
- description: Provides charset detection, locale sensitive collation and more. Depends on libicu.
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ description: Provides charset detection, locale sensitive collation and more. Depends
63
+ on libicu.
38
64
  email: jari.bakken@gmail.com
39
65
  executables: []
40
-
41
66
  extensions: []
42
-
43
- extra_rdoc_files:
67
+ extra_rdoc_files:
44
68
  - LICENSE
45
69
  - README.md
46
- files:
70
+ files:
47
71
  - .document
48
72
  - .gitignore
73
+ - .travis.yml
49
74
  - Gemfile
50
75
  - LICENSE
51
76
  - README.md
@@ -73,32 +98,30 @@ files:
73
98
  - test.c
74
99
  homepage: http://github.com/jarib/ffi-icu
75
100
  licenses: []
76
-
77
101
  post_install_message:
78
- rdoc_options:
102
+ rdoc_options:
79
103
  - --charset=UTF-8
80
- require_paths:
104
+ require_paths:
81
105
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
83
107
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: "0"
88
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
113
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
94
118
  requirements: []
95
-
96
119
  rubyforge_project:
97
- rubygems_version: 1.8.2
120
+ rubygems_version: 1.8.21
98
121
  signing_key:
99
122
  specification_version: 3
100
123
  summary: Simple Ruby FFI wrappers for things I need from ICU.
101
- test_files:
124
+ test_files:
102
125
  - spec/break_iterator_spec.rb
103
126
  - spec/chardet_spec.rb
104
127
  - spec/collation_spec.rb
@@ -106,3 +129,4 @@ test_files:
106
129
  - spec/spec.opts
107
130
  - spec/spec_helper.rb
108
131
  - spec/transliteration_spec.rb
132
+ has_rdoc: