Code Monkey home page Code Monkey logo

icunicode's Introduction

ICUnicode

Unicode sorting is complicated (unicode.org/reports/tr10), and Ruby doesn’t do it correctly. But there is a widely-used implementation of the Unicode collation algorithm in the ICU (International Components for Unicode) libraries. There is also no way to do Transliteration in Ruby (userguide.icu-project.org/transforms/general). This gem is a simple C wrapper around ucol_getSortKey from the ICU Collation API and utrans_transUChars from the ICU Transliteration API. These are added as simple methods on String.

Usage:

["cafe", "cafes", "caf\303\251"].sort
=> ["cafe", "cafes", "caf\303\251"]

require 'icunicode'

["cafe", "cafes", "caf\303\251"].sort_by {|s| s.unicode_sort_key}
=> ["cafe", "caf\303\251", "cafes"]

"blueberry".transliterate("Katakana").transliterate("Latin")
=> "burueberrui"

"blueberry".transliterate("Greek").transliterate("Latin")
=> "blyeberry"

Install:

You must install ICU first. You can download the source from site.icu-project.org/download, or on Mac, you can install with MacPorts:

sudo port install icu

Then install the gem:

sudo gem install icunicode

To do:

Add support for locales other than en-US. Increase buffer size or make it grow dynamically.

License:

Copyright © 2009 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.