14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
|
# File 'ext/utf8proc_native.c', line 14430
VALUE utf8proc_ruby_map(VALUE self, VALUE str_param, VALUE options_param) {
VALUE str;
int options;
VALUE env_obj;
utf8proc_ruby_mapenv_t *env;
ssize_t result;
VALUE retval;
str = StringValue(str_param);
options = NUM2INT(options_param) & ~UTF8PROC_NULLTERM;
env_obj = Data_Make_Struct(rb_cObject, utf8proc_ruby_mapenv_t, NULL,
utf8proc_ruby_mapenv_free, env);
result = utf8proc_decompose(RSTRING(str)->ptr, RSTRING(str)->len,
NULL, 0, options);
if (result < 0) {
utf8proc_ruby_map_error(result);
return Qnil; // needed to prevent problems with optimization
}
env->buffer = ALLOC_N(int32_t, result+1);
result = utf8proc_decompose(RSTRING(str)->ptr, RSTRING(str)->len,
env->buffer, result, options);
if (result < 0) {
free(env->buffer);
env->buffer = 0;
utf8proc_ruby_map_error(result);
return Qnil; // needed to prevent problems with optimization
}
result = utf8proc_reencode(env->buffer, result, options);
if (result < 0) {
free(env->buffer);
env->buffer = 0;
utf8proc_ruby_map_error(result);
return Qnil; // needed to prevent problems with optimization
}
retval = rb_str_new((char *)env->buffer, result);
free(env->buffer);
env->buffer = 0;
return retval;
}
|