diff options
author | Norman Clarke <norman@njclarke.com> | 2010-05-28 16:36:22 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-20 00:51:19 +0200 |
commit | 667522ca9834ce1f173a3421fb0bf0f555324c6f (patch) | |
tree | de11e65ee1b98c07066acb1848c2f9fdcb0f1f4c /activesupport/lib/active_support/multibyte/chars.rb | |
parent | 95a8f252c028c94b70cce4888bce42b7e9e30786 (diff) | |
download | rails-667522ca9834ce1f173a3421fb0bf0f555324c6f.tar.gz rails-667522ca9834ce1f173a3421fb0bf0f555324c6f.tar.bz2 rails-667522ca9834ce1f173a3421fb0bf0f555324c6f.zip |
Adds titleize/titlecase to AS::Multibyte::Chars
[#2794 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support/multibyte/chars.rb')
-rw-r--r-- | activesupport/lib/active_support/multibyte/chars.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index a275176b4a..04193bfa65 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -371,6 +371,16 @@ module ActiveSupport #:nodoc: (slice(0) || chars('')).upcase + (slice(1..-1) || chars('')).downcase end + # Capitalizes the first letter of every word, when possible. + # + # Example: + # "ÉL QUE SE ENTERÓ".mb_chars.titleize # => "Él Que Se Enteró" + # "日本語".mb_chars.titleize # => "日本語" + def titleize + chars(downcase.to_s.gsub(/\b('?[\S])/u) { Unicode.apply_mapping $1, :uppercase_mapping }) + end + alias_method :titlecase, :titleize + # Returns the KC normalization of the string by default. NFKC is considered the best normalization form for # passing strings to databases and validations. # |