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
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'ext/glib/glib.c', line 59
static VALUE utf8_downcase(VALUE self, VALUE string)
{
VALUE result;
gchar *temp;
Check_Type(string, T_STRING);
temp = g_utf8_strdown(StringValuePtr(string), RSTRING_LEN(string));
result = rb_str_new2(temp);
free(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]
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'ext/glib/glib.c', line 107
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_PTR(rb_inspect(form)));
}
temp = g_utf8_normalize(StringValuePtr(string), RSTRING_LEN(string), mode);
result = rb_str_new2(temp);
free(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
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'ext/glib/glib.c', line 80
static VALUE utf8_reverse(VALUE self, VALUE string)
{
VALUE result;
gchar *temp;
Check_Type(string, T_STRING);
temp = g_utf8_strreverse(StringValuePtr(string), RSTRING_LEN(string));
result = rb_str_new2(temp);
free(temp);
return result;
}
|
.utf8_size(string) ⇒ Object
Returns the length of the string expressed in codepoints.
Glib.utf8_size('A ehm…, word.') #=> 13
20 21 22 23 24 25 26 27 28 |
# File 'ext/glib/glib.c', line 20
static VALUE utf8_size(VALUE self, VALUE string)
{
VALUE result;
Check_Type(string, T_STRING);
result = ULONG2NUM(g_utf8_strlen(StringValuePtr(string), RSTRING_LEN(string)));
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
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'ext/glib/glib.c', line 38
static VALUE utf8_upcase(VALUE self, VALUE string)
{
VALUE result;
gchar *temp;
Check_Type(string, T_STRING);
temp = g_utf8_strup(StringValuePtr(string), RSTRING_LEN(string));
result = rb_str_new2(temp);
free(temp);
return result;
}
|