Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: unicode_normalize.rb
# coding: utf-8
[0] Fix | Delete
[1] Fix | Delete
# Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
[2] Fix | Delete
[3] Fix | Delete
# additions to class String for Unicode normalization
[4] Fix | Delete
class String
[5] Fix | Delete
# === Unicode Normalization
[6] Fix | Delete
#
[7] Fix | Delete
# :call-seq:
[8] Fix | Delete
# str.unicode_normalize(form=:nfc)
[9] Fix | Delete
#
[10] Fix | Delete
# Returns a normalized form of +str+, using Unicode normalizations
[11] Fix | Delete
# NFC, NFD, NFKC, or NFKD. The normalization form used is determined
[12] Fix | Delete
# by +form+, which is any of the four values :nfc, :nfd, :nfkc, or :nfkd.
[13] Fix | Delete
# The default is :nfc.
[14] Fix | Delete
#
[15] Fix | Delete
# If the string is not in a Unicode Encoding, then an Exception is raised.
[16] Fix | Delete
# In this context, 'Unicode Encoding' means any of UTF-8, UTF-16BE/LE,
[17] Fix | Delete
# and UTF-32BE/LE, as well as GB18030, UCS_2BE, and UCS_4BE. Anything
[18] Fix | Delete
# else than UTF-8 is implemented by converting to UTF-8,
[19] Fix | Delete
# which makes it slower than UTF-8.
[20] Fix | Delete
#
[21] Fix | Delete
# _Examples_
[22] Fix | Delete
#
[23] Fix | Delete
# "a\u0300".unicode_normalize #=> 'à' (same as "\u00E0")
[24] Fix | Delete
# "a\u0300".unicode_normalize(:nfc) #=> 'à' (same as "\u00E0")
[25] Fix | Delete
# "\u00E0".unicode_normalize(:nfd) #=> 'à' (same as "a\u0300")
[26] Fix | Delete
# "\xE0".force_encoding('ISO-8859-1').unicode_normalize(:nfd)
[27] Fix | Delete
# #=> Encoding::CompatibilityError raised
[28] Fix | Delete
#
[29] Fix | Delete
def unicode_normalize(form = :nfc)
[30] Fix | Delete
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
[31] Fix | Delete
## The following line can be uncommented to avoid repeated checking for
[32] Fix | Delete
## UnicodeNormalize. However, tests didn't show any noticeable speedup
[33] Fix | Delete
## when doing this. This comment also applies to the commented out lines
[34] Fix | Delete
## in String#unicode_normalize! and String#unicode_normalized?.
[35] Fix | Delete
# String.send(:define_method, :unicode_normalize, ->(form = :nfc) { UnicodeNormalize.normalize(self, form) } )
[36] Fix | Delete
UnicodeNormalize.normalize(self, form)
[37] Fix | Delete
end
[38] Fix | Delete
[39] Fix | Delete
# :call-seq:
[40] Fix | Delete
# str.unicode_normalize!(form=:nfc)
[41] Fix | Delete
#
[42] Fix | Delete
# Destructive version of String#unicode_normalize, doing Unicode
[43] Fix | Delete
# normalization in place.
[44] Fix | Delete
#
[45] Fix | Delete
def unicode_normalize!(form = :nfc)
[46] Fix | Delete
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
[47] Fix | Delete
# String.send(:define_method, :unicode_normalize!, ->(form = :nfc) { replace(unicode_normalize(form)) } )
[48] Fix | Delete
replace(unicode_normalize(form))
[49] Fix | Delete
end
[50] Fix | Delete
[51] Fix | Delete
# :call-seq:
[52] Fix | Delete
# str.unicode_normalized?(form=:nfc)
[53] Fix | Delete
#
[54] Fix | Delete
# Checks whether +str+ is in Unicode normalization form +form+,
[55] Fix | Delete
# which is any of the four values :nfc, :nfd, :nfkc, or :nfkd.
[56] Fix | Delete
# The default is :nfc.
[57] Fix | Delete
#
[58] Fix | Delete
# If the string is not in a Unicode Encoding, then an Exception is raised.
[59] Fix | Delete
# For details, see String#unicode_normalize.
[60] Fix | Delete
#
[61] Fix | Delete
# _Examples_
[62] Fix | Delete
#
[63] Fix | Delete
# "a\u0300".unicode_normalized? #=> false
[64] Fix | Delete
# "a\u0300".unicode_normalized?(:nfd) #=> true
[65] Fix | Delete
# "\u00E0".unicode_normalized? #=> true
[66] Fix | Delete
# "\u00E0".unicode_normalized?(:nfd) #=> false
[67] Fix | Delete
# "\xE0".force_encoding('ISO-8859-1').unicode_normalized?
[68] Fix | Delete
# #=> Encoding::CompatibilityError raised
[69] Fix | Delete
#
[70] Fix | Delete
def unicode_normalized?(form = :nfc)
[71] Fix | Delete
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
[72] Fix | Delete
# String.send(:define_method, :unicode_normalized?, ->(form = :nfc) { UnicodeNormalize.normalized?(self, form) } )
[73] Fix | Delete
UnicodeNormalize.normalized?(self, form)
[74] Fix | Delete
end
[75] Fix | Delete
end
[76] Fix | Delete
[77] Fix | Delete
[78] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function