class ICU::Locale
Attributes
id[R]
to_s[R]
Public Class Methods
available()
click to toggle source
# File lib/ffi-icu/locale.rb, line 4 def available (0...Lib.uloc_countAvailable).map do |idx| Locale.new(Lib.uloc_getAvailable(idx)) end end
default()
click to toggle source
# File lib/ffi-icu/locale.rb, line 10 def default Locale.new(Lib.uloc_getDefault) end
default=(locale)
click to toggle source
# File lib/ffi-icu/locale.rb, line 14 def default=(locale) Lib.check_error { |status| Lib.uloc_setDefault(locale.to_s, status) } end
for_language_tag(tag)
click to toggle source
# File lib/ffi-icu/locale.rb, line 18 def for_language_tag(tag) result = Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_forLanguageTag(tag, buffer, buffer.size, nil, status) end Locale.new(result) end
for_lcid(id)
click to toggle source
# File lib/ffi-icu/locale.rb, line 26 def for_lcid(id) result = Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getLocaleForLCID(id, buffer, buffer.size, status) end Locale.new(result) end
iso_countries()
click to toggle source
# File lib/ffi-icu/locale.rb, line 34 def iso_countries Lib::Util.read_null_terminated_array_of_strings(Lib.uloc_getISOCountries) end
iso_languages()
click to toggle source
# File lib/ffi-icu/locale.rb, line 38 def iso_languages Lib::Util.read_null_terminated_array_of_strings(Lib.uloc_getISOLanguages) end
new(id)
click to toggle source
# File lib/ffi-icu/locale.rb, line 45 def initialize(id) @id = id.to_s end
Public Instance Methods
==(other)
click to toggle source
# File lib/ffi-icu/locale.rb, line 49 def ==(other) other.is_a?(self.class) && other.id == self.id end
base_name()
click to toggle source
# File lib/ffi-icu/locale.rb, line 53 def base_name Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getBaseName(@id, buffer, buffer.size, status) end end
canonical()
click to toggle source
# File lib/ffi-icu/locale.rb, line 59 def canonical Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_canonicalize(@id, buffer, buffer.size, status) end end
character_orientation()
click to toggle source
# File lib/ffi-icu/locale.rb, line 65 def character_orientation Lib.check_error { |status| Lib.uloc_getCharacterOrientation(@id, status) } end
country()
click to toggle source
# File lib/ffi-icu/locale.rb, line 69 def country Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getCountry(@id, buffer, buffer.size, status) end end
display_country(locale = nil)
click to toggle source
# File lib/ffi-icu/locale.rb, line 75 def display_country(locale = nil) locale = locale.to_s unless locale.nil? Lib::Util.read_uchar_buffer(256) do |buffer, status| Lib.uloc_getDisplayCountry(@id, locale, buffer, buffer.size, status) end end
display_language(locale = nil)
click to toggle source
# File lib/ffi-icu/locale.rb, line 83 def display_language(locale = nil) locale = locale.to_s unless locale.nil? Lib::Util.read_uchar_buffer(192) do |buffer, status| Lib.uloc_getDisplayLanguage(@id, locale, buffer, buffer.size, status) end end
display_name(locale = nil)
click to toggle source
# File lib/ffi-icu/locale.rb, line 91 def display_name(locale = nil) locale = locale.to_s unless locale.nil? Lib::Util.read_uchar_buffer(256) do |buffer, status| Lib.uloc_getDisplayName(@id, locale, buffer, buffer.size, status) end end
display_script(locale = nil)
click to toggle source
# File lib/ffi-icu/locale.rb, line 99 def display_script(locale = nil) locale = locale.to_s unless locale.nil? Lib::Util.read_uchar_buffer(128) do |buffer, status| Lib.uloc_getDisplayScript(@id, locale, buffer, buffer.size, status) end end
display_variant(locale = nil)
click to toggle source
# File lib/ffi-icu/locale.rb, line 107 def display_variant(locale = nil) locale = locale.to_s unless locale.nil? Lib::Util.read_uchar_buffer(64) do |buffer, status| Lib.uloc_getDisplayVariant(@id, locale, buffer, buffer.size, status) end end
iso_country()
click to toggle source
# File lib/ffi-icu/locale.rb, line 115 def iso_country Lib.uloc_getISO3Country(@id) end
iso_language()
click to toggle source
# File lib/ffi-icu/locale.rb, line 119 def iso_language Lib.uloc_getISO3Language(@id) end
keyword(keyword)
click to toggle source
# File lib/ffi-icu/locale.rb, line 123 def keyword(keyword) Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getKeywordValue(@id, keyword.to_s, buffer, buffer.size, status) end end
keywords()
click to toggle source
# File lib/ffi-icu/locale.rb, line 129 def keywords enum_ptr = Lib.check_error { |status| Lib.uloc_openKeywords(@id, status) } begin Lib.enum_ptr_to_array(enum_ptr) ensure Lib.uenum_close(enum_ptr) end end
language()
click to toggle source
# File lib/ffi-icu/locale.rb, line 139 def language Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getLanguage(@id, buffer, buffer.size, status) end end
lcid()
click to toggle source
# File lib/ffi-icu/locale.rb, line 145 def lcid Lib.uloc_getLCID(@id) end
line_orientation()
click to toggle source
# File lib/ffi-icu/locale.rb, line 149 def line_orientation Lib.check_error { |status| Lib.uloc_getLineOrientation(@id, status) } end
name()
click to toggle source
# File lib/ffi-icu/locale.rb, line 153 def name Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getName(@id, buffer, buffer.size, status) end end
parent()
click to toggle source
# File lib/ffi-icu/locale.rb, line 159 def parent Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getParent(@id, buffer, buffer.size, status) end end
script()
click to toggle source
# File lib/ffi-icu/locale.rb, line 165 def script Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getScript(@id, buffer, buffer.size, status) end end
to_language_tag(strict = false)
click to toggle source
# File lib/ffi-icu/locale.rb, line 171 def to_language_tag(strict = false) Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_toLanguageTag(@id, buffer, buffer.size, strict ? 1 : 0, status) end end
variant()
click to toggle source
# File lib/ffi-icu/locale.rb, line 179 def variant Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_getVariant(@id, buffer, buffer.size, status) end end
with_keyword(keyword, value)
click to toggle source
# File lib/ffi-icu/locale.rb, line 185 def with_keyword(keyword, value) keyword = keyword.to_s length = @id.length + keyword.length + 64 unless value.nil? value = value.to_s length += value.length end result = Lib::Util.read_string_buffer(length) do |buffer, status| buffer.write_string(@id) Lib.uloc_setKeywordValue(keyword, value, buffer, buffer.size, status) end Locale.new(result) end
with_keywords(hash)
click to toggle source
# File lib/ffi-icu/locale.rb, line 202 def with_keywords(hash) hash.reduce(self) do |locale, (keyword, value)| locale.with_keyword(keyword, value) end end