Unichars 0.2 released
Unichars is a simple wrapper around Glib2 Unicode functions. You can use it to speed up certain methods on Unicode string. Currently supported are: upcase
, downcase
, reverse
, and size
. The cool thing about it is that it works seamlessly with ActiveSupport::Multibyte and it works great without ActiveSupport::Multibyte.
I know Unichars is not a very exiting name like God, Vlad the Deployer, or Gerard Joling but I guess I’m not that kind of a guy.
You can install Unichars with Rubygems:
Or you can fetch it from Github:
With Rails
The examples in the README tell you how to use Unichars with Rails 2.1 or newer. I’ll just re-iterate how it’s done.
First you make sure you load the library, the easiest way to do this is with config.gem
in environment.rb
:
Or when you dislike gems, you can just require it:
When you’re not using config.gem
, you have to make sure ActiveSupport is loaded before Unichars, otherwise the Rails integration won’t magically work.
After that you have to tell ActiveSupport::Multibyte to use the Unichars class as proxy class. You can do that in an initializer or at the end of your environment.rb. I would recommend doing it in config/initializers/unichars.rb
.
Now all of Rails will automatically use the Unichars character proxy, you can also use it yourself:
Without Rails, but with ActiveSupport
Other than that it’s similar to Rails:
A good time to talk about LC_CTYPE
real quick. Note that Glib2 picks that up from your environment, so your results may vary depending on what it’s set too.
Without training wheels
If you don’t use ActiveSupport, you can still use Unichars because it comes with a light version of the Chars proxy. You will have to wire it yourself though:
Without anything
Finally, you can just use the Glib2 wrapper and roll your own solution:
Questions?
If you have any questions or issues, please use the Github Wiki Wiki as much as possible. If you want to discuss anything you can find me on Freenode in #rails-contrib. Have fun with Unichars!