mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
5fee67c9ba
* lib/unicode_normalize.rb: Remove definition of String#unicode_normalize (including documentation) * string.c: Define String#unicode_normalize in rb_str_unicode_normalize in C, (including documentation) * lib/unicode_normalize/normalize.rb: Remove (re)definition of String#unicode_normalize to avoid warnings (when $VERBOSE==true) and problems when String is frozen git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
44 lines
1.3 KiB
Ruby
44 lines
1.3 KiB
Ruby
# coding: utf-8
|
|
# frozen_string_literal: false
|
|
|
|
# Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
|
|
|
|
#--
|
|
# additions to class String for Unicode normalization
|
|
#++
|
|
class String
|
|
|
|
# :call-seq:
|
|
# str.unicode_normalize!(form=:nfc)
|
|
#
|
|
# Destructive version of String#unicode_normalize, doing Unicode
|
|
# normalization in place.
|
|
#
|
|
def unicode_normalize!(form = :nfc)
|
|
require 'unicode_normalize/normalize.rb'
|
|
unicode_normalize! form
|
|
end
|
|
|
|
# :call-seq:
|
|
# str.unicode_normalized?(form=:nfc)
|
|
#
|
|
# Checks whether +str+ is in Unicode normalization form +form+,
|
|
# which can be any of the four values +:nfc+, +:nfd+, +:nfkc+, or +:nfkd+.
|
|
# The default is +:nfc+.
|
|
#
|
|
# If the string is not in a Unicode Encoding, then an Exception is raised.
|
|
# For details, see String#unicode_normalize.
|
|
#
|
|
# "a\u0300".unicode_normalized? #=> false
|
|
# "a\u0300".unicode_normalized?(:nfd) #=> true
|
|
# "\u00E0".unicode_normalized? #=> true
|
|
# "\u00E0".unicode_normalized?(:nfd) #=> false
|
|
# "\xE0".force_encoding('ISO-8859-1').unicode_normalized?
|
|
# #=> Encoding::CompatibilityError raised
|
|
#
|
|
def unicode_normalized?(form = :nfc)
|
|
require 'unicode_normalize/normalize.rb'
|
|
unicode_normalized? form
|
|
end
|
|
end
|
|
|