ffi-icu
Simple FFI wrappers for things I need from ICU. For the full thing, check out ICU4R instead.
Gem
-
gem install ffi-icu
Dependencies
ICU. If you get messages that the library or functions are not found, you can set some environment varibles to tell ffi-icu where to find it, i.e.:
FFI_ICU_LIB="icui18n.so" FFI_ICU_VERSION_SUFFIX="_3_8" ruby -r ffi-icu
Features
Character Encoding Detection
Examples:
match = ICU::CharDet.detect(str)
match.name # => "UTF-8"
match.confidence # => 80
or
detector = ICU::CharDet::Detector.new
detector.detect(str)
detector.close
Why not just use rchardet?
-
this is faster
-
rchardet does not work well on 1.9
-
none of the rchardet forks claiming to work on 1.9 actually does
Locale Sensitive Collation
Examples:
ICU::Collation.collate("nb", %w[å æ ø]) == %w[æ ø å] #=> true
or
collator = ICU::Collation::Collator.new("nb")
collator.compare("a", "b") #=> -1
collator.greater?("z", "a") #=> true
collator.collate(%w[å æ ø]) #=> ["æ", "ø", "å"]
Tested on:
Platforms:
-
OS X 10.6
-
Debian Linux
-
Arch Linux
Rubies:
-
MRI 1.9.1
-
MRI 1.8.7
TODO:
-
Useful ICU stuff:
-
number formatting (decimal points, thousand separators, currency)
-
date formatting
-
-
Windows?!
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2010-2011 Jari Bakken. See LICENSE for details.