Module: GLib::UCS4
- Defined in:
- ext/glib2/rbglib_unicode.c
Class Method Summary collapse
Class Method Details
.to_utf16(rb_ucs4) ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/glib2/rbglib_unicode.c', line 401
static VALUE
rbglib_m_ucs4_to_utf16(VALUE self, VALUE rb_ucs4)
{
VALUE result;
gunichar *ucs4;
gunichar2 *utf16;
glong len, items_written;
GError *error = NULL;
ucs4 = (gunichar *)StringValuePtr(rb_ucs4);
len = RSTRING_LEN(rb_ucs4) / sizeof(*ucs4);
utf16 = g_ucs4_to_utf16(ucs4, len, NULL, &items_written, &error);
if (error)
RAISE_GERROR(error);
result = rb_str_new((char *)utf16, items_written * sizeof(*utf16));
g_free(utf16);
return result;
}
|
.to_utf8(rb_ucs4) ⇒ Object
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'ext/glib2/rbglib_unicode.c', line 423
static VALUE
rbglib_m_ucs4_to_utf8(VALUE self, VALUE rb_ucs4)
{
VALUE result;
gunichar *ucs4;
gchar *utf8;
glong len, items_written;
GError *error = NULL;
ucs4 = (gunichar *)StringValuePtr(rb_ucs4);
len = RSTRING_LEN(rb_ucs4) / sizeof(*ucs4);
utf8 = g_ucs4_to_utf8(ucs4, len, NULL, &items_written, &error);
if (error)
RAISE_GERROR(error);
result = rb_str_new(utf8, items_written);
g_free(utf8);
return result;
}
|