Module: Glib
- Defined in:
- ext/glib/glib.c
Class Method Summary collapse
-
.utf8_downcase(string) ⇒ Object
Returns the string in lowercase characters if they are are available for the supplied characters.
-
.utf_normalize(string, form) ⇒ Object
Returns the normalized form of the string.
-
.utf8_reverse(string) ⇒ Object
Returns a string with the characters in reverse order.
-
.utf8_size(string) ⇒ Object
Returns the length of the string expressed in codepoints.
-
.utf8_upcase(string) ⇒ Object
Returns the string in capitals if they are are available for the supplied characters.
Class Method Details
.utf8_downcase(string) ⇒ Object
Returns the string in lowercase characters if they are are available for the supplied characters.
Glib.utf8_downcase('ORGANISÉE') #=> organisée
50 51 52 53 54 55 56 57 58 59 60 |
# File 'ext/glib/glib.c', line 50
static VALUE utf8_downcase(VALUE self, VALUE string)
{
VALUE result;
gchar *temp;
Check_Type(string, T_STRING);
temp = g_utf8_strdown(StringValuePtr(string), RSTRING(string)->len);
result = rb_str_new2(temp);
return result;
}
|
.utf_normalize(string, form) ⇒ Object
Returns the normalized form of the string. See www.unicode.org/reports/tr15/tr15-29.html for more information about normalization.
form can be one of the following: :c
, :kc
, :d
, or :kd
.
decomposed = [101, 769].pack('U*')
composed = Glib.utf8_normalize(decomposed, :kc)
composed.unpack('U*') #=> [233]
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'ext/glib/glib.c', line 96
static VALUE utf8_normalize(VALUE self, VALUE string, VALUE form)
{
VALUE result;
gchar *temp;
GNormalizeMode mode;
Check_Type(string, T_STRING);
Check_Type(form, T_SYMBOL);
if (ID2SYM(rb_intern("d")) == form) {
mode = G_NORMALIZE_NFD;
} else if (ID2SYM(rb_intern("c")) == form) {
mode = G_NORMALIZE_NFC;
} else if (ID2SYM(rb_intern("kd")) == form) {
mode = G_NORMALIZE_NFKD;
} else if (ID2SYM(rb_intern("kc")) == form) {
mode = G_NORMALIZE_NFKC;
} else {
rb_raise(rb_eArgError, "%s is not a valid normalization form, options are: :d, :kd, :c, or :kc", RSTRING(rb_inspect(form))->ptr);
}
temp = g_utf8_normalize(StringValuePtr(string), RSTRING(string)->len, mode);
result = rb_str_new2(temp);
return result;
}
|
.utf8_reverse(string) ⇒ Object
Returns a string with the characters in reverse order.
Glib.utf8_reverse('Comment ça va?') #=> av aç tnemmoC
70 71 72 73 74 75 76 77 78 79 80 |
# File 'ext/glib/glib.c', line 70
static VALUE utf8_reverse(VALUE self, VALUE string)
{
VALUE result;
gchar *temp;
Check_Type(string, T_STRING);
temp = g_utf8_strreverse(StringValuePtr(string), RSTRING(string)->len);
result = rb_str_new2(temp);
return result;
}
|
.utf8_size(string) ⇒ Object
Returns the length of the string expressed in codepoints.
Glib.utf8_size('A ehm…, word.') #=> 13
12 13 14 15 16 17 18 19 20 |
# File 'ext/glib/glib.c', line 12
static VALUE utf8_size(VALUE self, VALUE string)
{
VALUE result;
Check_Type(string, T_STRING);
result = ULONG2NUM(g_utf8_strlen(StringValuePtr(string), RSTRING(string)->len));
return result;
}
|
.utf8_upcase(string) ⇒ Object
Returns the string in capitals if they are are available for the supplied characters.
Glib.utf8_upcase('Sluß') #=> SLUSS
30 31 32 33 34 35 36 37 38 39 40 |
# File 'ext/glib/glib.c', line 30
static VALUE utf8_upcase(VALUE self, VALUE string)
{
VALUE result;
gchar *temp;
Check_Type(string, T_STRING);
temp = g_utf8_strup(StringValuePtr(string), RSTRING(string)->len);
result = rb_str_new2(temp);
return result;
}
|