module IDN::Stringprep

The Stringprep module of LibIDN Ruby Bindings.

Example usage

require 'idn'
include IDN

str = Stringprep.with_profile('FOO', 'Nameprep')

Public Class Methods

IDN::Stringprep.nameprep(string) → string click to toggle source

Prepares a string in UTF-8 format according to the 'Nameprep' profile.

Raises IDN::Stringprep::StringprepError on failure.

static VALUE nameprep(VALUE self, VALUE str)
{
  return stringprep_internal(str, "Nameprep");
}
IDN::Stringprep.nfkc_normalize(string) → string click to toggle source

Converts a string in UTF-8 format into canonical form, standardizing such issues as whether a character with an accent is represented as a base character and combining accent or as a single precomposed character.

static VALUE nfkc_normalize(VALUE self, VALUE str)
{
  char *buf;
  VALUE retv;

  str = rb_check_convert_type(str, T_STRING, "String", "to_s");
  buf = stringprep_utf8_nfkc_normalize(RSTRING_PTR(str), RSTRING_LEN(str));

  retv = rb_str_new2(buf);
  xfree(buf);
  return retv;
}
IDN::Stringprep.nodeprep(string) → string click to toggle source

Prepares a string in UTF-8 format according to the 'Nodeprep' profile.

Raises IDN::Stringprep::StringprepError on failure.

static VALUE nodeprep(VALUE self, VALUE str)
{
  return stringprep_internal(str, "Nodeprep");
}
IDN::Stringprep.resourceprep(string) → string click to toggle source

Prepares a string in UTF-8 format according to the 'Resourceprep' profile.

Raises IDN::Stringprep::StringprepError on failure.

static VALUE resourceprep(VALUE self, VALUE str)
{
  return stringprep_internal(str, "Resourceprep");
}
IDN::Stringprep.with_profile(string, profile) → string click to toggle source

Prepares a string in UTF-8 format according to the given stringprep profile name which must be one of the internally supported stringprep profiles (for details see IANA's Profile Names in RFC3454).

Raises IDN::Stringprep::StringprepError on failure.

static VALUE with_profile(VALUE self, VALUE str, VALUE profile)
{
  profile = rb_check_convert_type(profile, T_STRING, "String", "to_s");
  return stringprep_internal(str, RSTRING_PTR(profile));
}