Module: Encoding::Character::Unicode::Codepoint

Defined in:
ext/encoding/character/unicode/codepoint.c

Class Method Summary collapse

Class Method Details

.from_utf8Object



25
26
27
28
29
30
31
32
33
# File 'ext/encoding/character/unicode/codepoint.c', line 25

static VALUE
rb_codepoint_from_utf8(UNUSED(VALUE self), VALUE str)
{
        StringValue(str);

        const char *s = RSTRING(str)->ptr;
        const char *end = s + RSTRING(str)->len;
        return INT2FIX(_utf_char_validated(s, end));
}

.to_utf8Object

TODO: undecided



15
16
17
18
19
20
21
22
23
# File 'ext/encoding/character/unicode/codepoint.c', line 15

static VALUE
rb_codepoint_to_utf8(UNUSED(VALUE self), VALUE codepoint)
{
        /* TODO: validate input */
        char buf[MAX_UNICHAR_BYTE_LENGTH];
        int len = unichar_to_utf(FIX2UINT(codepoint), buf);

        return rb_utf_new(buf, len);
}