Addressable::IDNA

Constants

ACE_MAX_LENGTH
ACE_PREFIX
COMPOSITION_TABLE
HANGUL_LBASE
HANGUL_LCOUNT
HANGUL_NCOUNT
HANGUL_SBASE
HANGUL_SCOUNT
HANGUL_TBASE
HANGUL_TCOUNT
HANGUL_VBASE
HANGUL_VCOUNT
PUNYCODE_BASE
PUNYCODE_DAMP
PUNYCODE_DELIMITER
PUNYCODE_INITIAL_BIAS
PUNYCODE_INITIAL_N
PUNYCODE_MAXINT
PUNYCODE_PRINT_ASCII
PUNYCODE_SKEW
PUNYCODE_TMAX
PUNYCODE_TMIN
UNICODE_DATA

This is a sparse Unicode table. Codepoints without entries are assumed to have the value: [0, 0, nil, nil, nil, nil, nil]

UNICODE_DATA_CANONICAL
UNICODE_DATA_COMBINING_CLASS
UNICODE_DATA_COMPATIBILITY
UNICODE_DATA_EXCLUSION
UNICODE_DATA_LOWERCASE
UNICODE_DATA_TITLECASE
UNICODE_DATA_UPPERCASE
UNICODE_MAX_LENGTH
UNICODE_TABLE

This module is loosely based on idn_actionmailer by Mick Staugaard, the unicode library by Yoshida Masato, and the punycode implementation by Kazuhiro Nishiyama. Most of the code was copied verbatim, but some reformatting was done, and some translation from C was done.

Without their code to work from as a base, we'd all still be relying on the presence of libidn. Which nobody ever seems to have installed.

Original sources: github.com/staugaard/idn_actionmailer www.yoshidam.net/Ruby.html#unicode rubyforge.org/frs/?group_id=2550

UTF8_REGEX
UTF8_REGEX_MULTIBYTE

Public Class Methods

to_ascii(input) click to toggle source

Converts from a Unicode internationalized domain name to an ASCII domain name as described in RFC 3490.

# File lib/addressable/idna/pure.rb, line 65
def self.to_ascii(input)
  input = input.dup
  if input.respond_to?(:force_encoding)
    input.force_encoding(Encoding::ASCII_8BIT)
  end
  if input =~ UTF8_REGEX && input =~ UTF8_REGEX_MULTIBYTE
    parts = unicode_downcase(input).split('.')
    parts.map! do |part|
      if part.respond_to?(:force_encoding)
        part.force_encoding(Encoding::ASCII_8BIT)
      end
      if part =~ UTF8_REGEX && part =~ UTF8_REGEX_MULTIBYTE
        ACE_PREFIX + punycode_encode(unicode_normalize_kc(part))
      else
        part
      end
    end
    parts.join('.')
  else
    input
  end
end
to_unicode(input) click to toggle source

Converts from an ASCII domain name to a Unicode internationalized domain name as described in RFC 3490.

# File lib/addressable/idna/pure.rb, line 90
def self.to_unicode(input)
  parts = input.split('.')
  parts.map! do |part|
    if part =~ /^#{ACE_PREFIX}/
      punycode_decode(part[/^#{ACE_PREFIX}(.+)/, 1])
    else
      part
    end
  end
  output = parts.join('.')
  if output.respond_to?(:force_encoding)
    output.force_encoding(Encoding::UTF_8)
  end
  output
end
unicode_normalize_kc(input) click to toggle source

Unicode normalization form KC.

# File lib/addressable/idna/pure.rb, line 107
def self.unicode_normalize_kc(input)
  unpacked = input.unpack("U*")
  unpacked =
    unicode_compose(unicode_sort_canonical(unicode_decompose(unpacked)))
  return unpacked.pack("U*")
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.