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



14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
# File 'ext/utf8proc_native.c', line 14438

static VALUE utf8proc_ruby_char(VALUE self, VALUE code_param) {
  char buffer[4];
  ssize_t result;
  int uc;
  uc = NUM2INT(code_param);
  if (!utf8proc_codepoint_valid(uc))
    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



14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
# File 'ext/utf8proc_native.c', line 14399

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