aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/multibyte
diff options
context:
space:
mode:
authorNorman Clarke <norman@njclarke.com>2012-01-06 12:06:26 -0300
committerNorman Clarke <norman@njclarke.com>2012-01-06 12:06:26 -0300
commitcac15643cf5c62dddf672bfaf239b42c1e108d19 (patch)
tree5814296f341f83adcd63960ae977d8f69f840b85 /activesupport/lib/active_support/multibyte
parentfc956425d405e75bcf310f3e6f08cf201cc8131a (diff)
downloadrails-cac15643cf5c62dddf672bfaf239b42c1e108d19.tar.gz
rails-cac15643cf5c62dddf672bfaf239b42c1e108d19.tar.bz2
rails-cac15643cf5c62dddf672bfaf239b42c1e108d19.zip
Implement Chars#swapcase.
Diffstat (limited to 'activesupport/lib/active_support/multibyte')
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb8
-rw-r--r--activesupport/lib/active_support/multibyte/unicode.rb8
2 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index 99b974e4a7..d69bfefc23 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -118,6 +118,14 @@ module ActiveSupport #:nodoc:
chars Unicode.downcase(@wrapped_string)
end
+ # Converts characters in the string to the opposite case.
+ #
+ # Example:
+ # 'El Cañón".mb_chars.swapcase.to_s # => "eL cAÑÓN"
+ def swapcase
+ chars Unicode.swapcase(@wrapped_string)
+ end
+
# Converts the first character to uppercase and the remainder to lowercase.
#
# Example:
diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb
index 94fb0a48aa..a0a8f3c97e 100644
--- a/activesupport/lib/active_support/multibyte/unicode.rb
+++ b/activesupport/lib/active_support/multibyte/unicode.rb
@@ -293,9 +293,17 @@ module ActiveSupport
apply_mapping string, :uppercase_mapping
end
+ def swapcase(string)
+ apply_mapping string, :swapcase_mapping
+ end
+
# Holds data about a codepoint in the Unicode database
class Codepoint
attr_accessor :code, :combining_class, :decomp_type, :decomp_mapping, :uppercase_mapping, :lowercase_mapping
+
+ def swapcase_mapping
+ uppercase_mapping > 0 ? uppercase_mapping : lowercase_mapping
+ end
end
# Holds static data from the Unicode database