Module: Utf8Proc

Defined in:
lib/utf8proc.rb,
ext/utf8proc_native.c

Defined Under Namespace

Modules: IntegerExtensions, StringExtensions Classes: CodeNotAssignedError, InvalidUtf8Error, UnicodeError

Constant Summary collapse

SpecialChars =
{
  :HT => "\x09",
  :LF => "\x0A",
  :VT => "\x0B",
  :FF => "\x0C",
  :CR => "\x0D",
  :FS => "\x1C",
  :GS => "\x1D",
  :RS => "\x1E",
  :US => "\x1F",
  :LS => "\xE2\x80\xA8",
  :PS => "\xE2\x80\xA9",
}
Options =
utf8proc_ruby_options

Class Method Summary collapse

Class Method Details

.utf8char(code_param) ⇒ Object



14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
# File 'ext/utf8proc_native.c', line 14469

static VALUE utf8proc_ruby_char(VALUE self, VALUE code_param) {
  char buffer[4];
  ssize_t result;
  int uc;
  uc = NUM2INT(code_param);
  if (uc < 0 || uc >= 0x110000 ||
      ((uc & 0xFFFF) >= 0xFFFE) || (uc >= 0xD800 && uc < 0xE000) ||
      (uc >= 0xFDD0 && uc < 0xFDF0))
    rb_raise(rb_eArgError, "Invalid Unicode code point");
  result = utf8proc_encode_char(uc, buffer);
  return rb_str_new(buffer, result);
}

.utf8map(str_param, options_param) ⇒ Object



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;
}