Module: GLib::UTF8

Defined in:
ext/glib2/rbglib_unicode.c

Class Method Summary collapse

Class Method Details

.casefold(rb_utf8) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
# File 'ext/glib2/rbglib_unicode.c', line 245

static VALUE
rbglib_m_utf8_casefold(VALUE self, VALUE rb_utf8)
{
    VALUE result;
    gchar *utf8, *casefolded_utf8;

    utf8 = StringValueCStr(rb_utf8);
    casefolded_utf8 = g_utf8_casefold(utf8, RSTRING_LEN(rb_utf8));
    result = rb_str_new2(casefolded_utf8);
    g_free(casefolded_utf8);
    return result;
}

.collate(utf8a, utf8b) ⇒ Object



277
278
279
280
281
282
# File 'ext/glib2/rbglib_unicode.c', line 277

static VALUE
rbglib_m_utf8_collate(VALUE self, VALUE utf8a, VALUE utf8b)
{
    return INT2NUM(g_utf8_collate(StringValueCStr(utf8a),
                                  StringValueCStr(utf8b)));
}

.collate_key(*args) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'ext/glib2/rbglib_unicode.c', line 284

static VALUE
rbglib_m_utf8_collate_key(int argc, VALUE *argv, VALUE self)
{
    VALUE result, rb_utf8, for_filename;
    gchar *key, *utf8;
    gssize len;

    rb_scan_args(argc, argv, "11", &rb_utf8, &for_filename);

    utf8 = StringValueCStr(rb_utf8);
    len = RSTRING_LEN(rb_utf8);
#if GLIB_CHECK_VERSION(2,8,0)
    if (RVAL2CBOOL(for_filename))
        key = g_utf8_collate_key_for_filename(utf8, len);
    else
#endif
        key = g_utf8_collate_key(utf8, len);

    result = rb_str_new2(key);
    g_free(key);
    return result;
}

.downcase(rb_utf8) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
# File 'ext/glib2/rbglib_unicode.c', line 232

static VALUE
rbglib_m_utf8_strdown(VALUE self, VALUE rb_utf8)
{
    VALUE result;
    gchar *utf8, *downcased_utf8;

    utf8 = StringValueCStr(rb_utf8);
    downcased_utf8 = g_utf8_strdown(utf8, RSTRING_LEN(rb_utf8));
    result = rb_str_new2(downcased_utf8);
    g_free(downcased_utf8);
    return result;
}

.get_char(*args) ⇒ Object

Not implemented. g_utf8_next_char



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'ext/glib2/rbglib_unicode.c', line 165

static VALUE
rbglib_m_utf8_get_char(int argc, VALUE *argv, VALUE self)
{
    VALUE utf8, validate;
    gunichar result;

    rb_scan_args(argc, argv, "11", &utf8, &validate);

    if (RVAL2CBOOL(validate)) {
        StringValue(utf8);
        result = g_utf8_get_char_validated(RSTRING_PTR(utf8),
                                           RSTRING_LEN(utf8));
        if (result == (gunichar)-1) {
            return INT2NUM(-1);
        } else if (result == (gunichar)-2) {
            return INT2NUM(-2);
        }
    } else {
        result = g_utf8_get_char(StringValueCStr(utf8));
    }

    return UINT2NUM(result);
}

.normalize(*args) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'ext/glib2/rbglib_unicode.c', line 258

static VALUE
rbglib_m_utf8_normalize(int argc, VALUE *argv, VALUE self)
{
    VALUE rb_utf8, rb_mode, result;
    gchar *utf8, *normalized_utf8;
    GNormalizeMode mode = G_NORMALIZE_DEFAULT;

    rb_scan_args(argc, argv, "11", &rb_utf8, &rb_mode);

    if (!NIL_P(rb_mode))
        mode = RVAL2GENUM(rb_mode, G_TYPE_NORMALIZE_MODE);

    utf8 = StringValueCStr(rb_utf8);
    normalized_utf8 = g_utf8_normalize(utf8, RSTRING_LEN(rb_utf8), mode);
    result = rb_str_new2(normalized_utf8);
    g_free(normalized_utf8);
    return result;
}

.reverse(rb_utf8) ⇒ Object

Not implemented. g_utf8_strncpy g_utf8_strrchr



198
199
200
201
202
203
204
205
206
207
208
209
# File 'ext/glib2/rbglib_unicode.c', line 198

static VALUE
rbglib_m_utf8_strreverse(VALUE self, VALUE rb_utf8)
{
    VALUE result;
    gchar *utf8, *reversed_utf8;

    utf8 = StringValueCStr(rb_utf8);
    reversed_utf8 = g_utf8_strreverse(utf8, RSTRING_LEN(rb_utf8));
    result = rb_str_new2(reversed_utf8);
    g_free(reversed_utf8);
    return result;
}

.size(rb_utf8) ⇒ Object

Not implemented. g_utf8_offset_to_pointer g_utf8_pointer_to_offset g_utf8_prev_char g_utf8_find_next_char g_utf8_find_prev_char g_utf8_prev_char



189
190
191
192
193
194
195
196
# File 'ext/glib2/rbglib_unicode.c', line 189

static VALUE
rbglib_m_utf8_strlen(VALUE self, VALUE rb_utf8)
{
    gchar *utf8;

    utf8 = StringValueCStr(rb_utf8);
    return INT2NUM(g_utf8_strlen(utf8, RSTRING_LEN(rb_utf8)));
}

.to_ucs4(*args) ⇒ Object



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'ext/glib2/rbglib_unicode.c', line 329

static VALUE
rbglib_m_utf8_to_ucs4(int argc, VALUE *argv, VALUE self)
{
    VALUE result, rb_utf8, is_fast;
    gchar *utf8;
    gunichar *ucs4;
    glong len, items_written;

    rb_scan_args(argc, argv, "11", &rb_utf8, &is_fast);

    utf8 = StringValueCStr(rb_utf8);
    len = RSTRING_LEN(rb_utf8);

    if (RVAL2CBOOL(is_fast)) {
        ucs4 = g_utf8_to_ucs4_fast(utf8, len, &items_written);
    } else {
        GError *error = NULL;
        ucs4 = g_utf8_to_ucs4(utf8, len, NULL, &items_written, &error);

        if (error)
            RAISE_GERROR(error);
    }

    result = rb_str_new((char *)ucs4, items_written * sizeof(*ucs4));
    g_free(ucs4);
    return result;
}

.to_utf16(rb_utf8) ⇒ Object



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'ext/glib2/rbglib_unicode.c', line 307

static VALUE
rbglib_m_utf8_to_utf16(VALUE self, VALUE rb_utf8)
{
    VALUE result;
    gchar *utf8;
    gunichar2 *utf16;
    glong len, items_written;
    GError *error = NULL;

    utf8 = StringValueCStr(rb_utf8);
    len = RSTRING_LEN(rb_utf8);

    utf16 = g_utf8_to_utf16(utf8, 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;
}

.upcase(rb_utf8) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
# File 'ext/glib2/rbglib_unicode.c', line 219

static VALUE
rbglib_m_utf8_strup(VALUE self, VALUE rb_utf8)
{
    VALUE result;
    gchar *utf8, *upcased_utf8;

    utf8 = StringValueCStr(rb_utf8);
    upcased_utf8 = g_utf8_strup(utf8, RSTRING_LEN(rb_utf8));
    result = rb_str_new2(upcased_utf8);
    g_free(upcased_utf8);
    return result;
}

.validate(str) ⇒ Object



211
212
213
214
215
216
217
# File 'ext/glib2/rbglib_unicode.c', line 211

static VALUE
rbglib_m_utf8_validate(VALUE self, VALUE str)
{
    StringValue(str);
    return CBOOL2RVAL(g_utf8_validate(RSTRING_PTR(str), RSTRING_LEN(str),
                                      NULL));
}