summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-19 08:26:35 +0000
committerduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-19 08:26:35 +0000
commitf83c0b0ae7e2d92e17d94c9de28375b091554351 (patch)
treea72ff3696f4f67404a820f69777ce44ebd043ac2 /lib
parent982f0de1418e185b3d9e3aaf31fc5a76ffcf941d (diff)
lib/unicode_normalize.rb: Added documentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/unicode_normalize.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/unicode_normalize.rb b/lib/unicode_normalize.rb
index 909aa0528b..16c655be83 100644
--- a/lib/unicode_normalize.rb
+++ b/lib/unicode_normalize.rb
@@ -4,15 +4,64 @@
require 'unicode_normalize/normalize.rb'
+# additions to class String for Unicode normalization
class String
+ # === Unicode Normalization
+ #
+ # :call-seq:
+ # str.unicode_normalize(form=:nfc)
+ #
+ # Returns a normalized form of +str+, using Unicode normalizations
+ # NFC, NFD, NFKC, or NFKD. The normalization form used is determined
+ # by +form+, which is 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.
+ # In this context, 'Unicode Encoding' means any of UTF-8, UTF-16BE/LE,
+ # and UTF-32BE/LE. Currently, anything else than UTF-8 is implemented
+ # by converting to UTF-8, which makes it slower than UTF-8.
+ #
+ # _Examples_
+ #
+ # "a\u0300".unicode_normalize #=> 'à' (same as "\u00E0")
+ # "a\u0300".unicode_normalize(:nfc) #=> 'à' (same as "\u00E0")
+ # "\u00E0".unicode_normalize(:nfd) #=> 'à' (same as "a\u0300")
+ # "\xE0".force_encoding('ISO-8859-1').unicode_normalize(:nfd)
+ # #=> Encoding::CompatibilityError raised
+ #
def unicode_normalize(form = :nfc)
UnicodeNormalize.normalize(self, form)
end
+ # :call-seq:
+ # str.unicode_normalize(form=:nfc)
+ #
+ # Destructive version of String#unicode_normalize, doing Unicode
+ # normalization in place.
+ #
def unicode_normalize!(form = :nfc)
replace(self.normalize(form))
end
+ # :call-seq:
+ # str.unicode_normalized?(form=:nfc)
+ #
+ # Checks whether +str+ is in Unicode normalization form +form+,
+ # which is 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.
+ #
+ # _Examples_
+ #
+ # "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)
UnicodeNormalize.normalized?(self, form)
end