Go to file
Jari Bakken 3d301ad36e full backtrace 2014-10-22 18:00:21 +02:00
benchmark Yet another rename (more consistent with other FFI projects) 2010-05-10 20:28:20 +02:00
lib Bump version to 0.1.4 2014-10-22 17:44:26 +02:00
spec prefer 'plural' currency style over 'accounting' 2014-10-22 08:37:06 -05:00
.document Initial commit to icu-chardet-ffi. 2010-05-09 19:04:44 +02:00
.gitignore Bundler + RSpec 2 2011-05-27 16:49:47 +02:00
.travis.yml Fix travis versions 2014-01-02 16:44:23 +01:00
Gemfile Fix gemfile source 2014-03-26 21:28:10 +01:00
LICENSE Bump year in copyright. 2014-01-02 16:43:38 +01:00
README.md docs and clean up tests a bit 2014-10-22 08:31:11 -05:00
Rakefile full backtrace 2014-10-22 18:00:21 +02:00
ffi-icu.gemspec Bump ffi dependency. Closes #11. 2012-12-17 15:30:51 +01:00
test.c Fix failing transliteration spec 2010-05-29 01:44:12 +02:00

README.md

ffi-icu

Simple FFI wrappers for things I need from ICU. For the full thing, check out ICU4R instead.

Build Status

Gem

Rubygem

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, e.g.:

$ export FFI_ICU_LIB="icui18n.so"
$ export FFI_ICU_VERSION_SUFFIX="_3_8"
$ ruby -r ffi-icu program.rb

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) => #<struct ICU::CharDet::Detector::Match ...>

Why not just use rchardet?

  • speed
  • 1.9 support

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[å æ ø]) #=> ["æ", "ø", "å"]

Text Boundary Analysis

Examples:

    iterator = ICU::BreakIterator.new(:word, "en_US")
    iterator.text = "This is a sentence."
    iterator.to_a  #=> [0, 4, 5, 7, 8, 9, 10, 18, 19]

Number/Currency Formatting

Examples:

    # class method interface
    NumberFormatting.format_number("en", 1_000) #=> "1,000"
    NumberFormatting.format_number("de-DE", 1234.56) #=> "1.234,56"
    NumberFormatting.format_currency("en", 123.45, 'USD') #=> "$123.45"
    NumberFormatting.format_percent("en", 0.53, 'USD') #=> "53%"
    NumberFormatting.spell("en_US", 1_000) #=> "one thousand"

    # reusable formatting objects
    numf = NumberFormatting.create('fr-CA')
    numf.format(1000) #=> "1 000"

    curf = NumberFormatting.create('en-US', :currency)
    curf.format(1234.56, 'USD') #=> "$1,234.56"

Tested on:

Platforms:

  • OS X 10.6
  • 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 (c) 2010-2014 Jari Bakken. See LICENSE for details.