Returns the KC normalization of the string by default. NFKC is considered
the best normalization form for passing strings to databases and
validations.
str - The string to perform normalization on.
form - The form you want to normalize
in. Should be one of the following: :c, :kc, :d or :kd.
# File activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 289
def normalize(str, form=ActiveSupport::Multibyte::DEFAULT_NORMALIZATION_FORM)
# See http://www.unicode.org/reports/tr15, Table 1
codepoints = u_unpack(str)
case form
when :d
reorder_characters(decompose_codepoints(:canonical, codepoints))
when :c
compose_codepoints reorder_characters(decompose_codepoints(:canonical, codepoints))
when :kd
reorder_characters(decompose_codepoints(:compatability, codepoints))
when :kc
compose_codepoints reorder_characters(decompose_codepoints(:compatability, codepoints))
else
raise ArgumentError, "#{form} is not a valid normalization variant", caller
end.pack('U*')
end