Project

ffi-locale

0.0
No commit activity in last 3 years
No release in over 3 years
An FFI wrapper for the C library setlocale and localeconv functions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.0.9
 Project Readme

ffi-locale¶ ↑

Author: Sean O’Halpin

A simple FFI wrapper for the C library {FFI::Locale#setlocale setlocale} and {FFI::Locale#localeconv localeconv} functions.

You would typically use this to enable correct UTF-8 processing in an MRI Ruby 1.8.x script that makes low level widechar function calls via a C extension or FFI wrapper.

The {FFI::Locale#setlocale setlocale} call is not needed in 1.9.x or any version of JRuby.

See the documentation for {FFI::Locale#setlocale setlocale} and {FFI::Locale#localeconv localeconv} for usage.

See {FFI::Locale::LocaleConv} for the information returned by {FFI::Locale#localeconv}.

See +man setlocale+, +man localeconv+ and +man 7 locale+ for details.

Usage¶ ↑

You should call {FFI::Locale#setlocale setlocale} before calling {FFI::Locale#localeconv localeconv} otherwise you’ll get random values in the {FFI::Locale::LocaleConv} structure.

if RUBY_VERSION < '1.9.0'
  require 'ffi-locale'
  FFI::Locale.setlocale(FFI::Locale::LC_ALL, "")
end

locale = FFI::Locale.localeconv
p locale.currency_symbol          # => '£' for en_GB.UTF-8