This is a sparse Unicode table. Codepoints without entries are assumed to have the value: [0, 0, nil, nil, nil, nil, nil]
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
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
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 normalization form KC.
# File lib/addressable/idna/pure.rb, line 107 def self.unicode_normalize_kc(input) input = input.to_s unless input.is_a?(String) unpacked = input.unpack("U*") unpacked = unicode_compose(unicode_sort_canonical(unicode_decompose(unpacked))) return unpacked.pack("U*") end
Generated with the Darkfish Rdoc Generator 2.