mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Deprecate Unicode#downcase/upcase/swapcase.
Use String methods directly instead.
This commit is contained in:
parent
8df7ed3b88
commit
e52b223487
4 changed files with 21 additions and 32 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
* Deprecate `ActiveSupport::Multibyte::Unicode#downcase/upcase/swapcase` in favor of
|
||||||
|
`String#downcase/upcase/swapcase`.
|
||||||
|
|
||||||
|
*Francesco Rodríguez*
|
||||||
|
|
||||||
* Add `ActiveSupport::ParameterFilter`.
|
* Add `ActiveSupport::ParameterFilter`.
|
||||||
|
|
||||||
*Yoshiyuki Kinjo*
|
*Yoshiyuki Kinjo*
|
||||||
|
|
|
@ -120,27 +120,6 @@ module ActiveSupport #:nodoc:
|
||||||
slice(0...translate_offset(limit))
|
slice(0...translate_offset(limit))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Converts characters in the string to uppercase.
|
|
||||||
#
|
|
||||||
# 'Laurent, où sont les tests ?'.mb_chars.upcase.to_s # => "LAURENT, OÙ SONT LES TESTS ?"
|
|
||||||
def upcase
|
|
||||||
chars Unicode.upcase(@wrapped_string)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Converts characters in the string to lowercase.
|
|
||||||
#
|
|
||||||
# 'VĚDA A VÝZKUM'.mb_chars.downcase.to_s # => "věda a výzkum"
|
|
||||||
def downcase
|
|
||||||
chars Unicode.downcase(@wrapped_string)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Converts characters in the string to the opposite case.
|
|
||||||
#
|
|
||||||
# '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.
|
# Converts the first character to uppercase and the remainder to lowercase.
|
||||||
#
|
#
|
||||||
# 'über'.mb_chars.capitalize.to_s # => "Über"
|
# 'über'.mb_chars.capitalize.to_s # => "Über"
|
||||||
|
@ -153,7 +132,7 @@ module ActiveSupport #:nodoc:
|
||||||
# "ÉL QUE SE ENTERÓ".mb_chars.titleize.to_s # => "Él Que Se Enteró"
|
# "ÉL QUE SE ENTERÓ".mb_chars.titleize.to_s # => "Él Que Se Enteró"
|
||||||
# "日本語".mb_chars.titleize.to_s # => "日本語"
|
# "日本語".mb_chars.titleize.to_s # => "日本語"
|
||||||
def titleize
|
def titleize
|
||||||
chars(downcase.to_s.gsub(/\b('?\S)/u) { Unicode.upcase($1) })
|
chars(downcase.to_s.gsub(/\b('?\S)/u) { $1.upcase })
|
||||||
end
|
end
|
||||||
alias_method :titlecase, :titleize
|
alias_method :titlecase, :titleize
|
||||||
|
|
||||||
|
@ -205,7 +184,7 @@ module ActiveSupport #:nodoc:
|
||||||
to_s.as_json(options)
|
to_s.as_json(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
%w(capitalize downcase reverse tidy_bytes upcase).each do |method|
|
%w(capitalize reverse tidy_bytes).each do |method|
|
||||||
define_method("#{method}!") do |*args|
|
define_method("#{method}!") do |*args|
|
||||||
@wrapped_string = send(method, *args).to_s
|
@wrapped_string = send(method, *args).to_s
|
||||||
self
|
self
|
||||||
|
|
|
@ -115,16 +115,15 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def downcase(string)
|
%w(downcase upcase swapcase).each do |method|
|
||||||
string.downcase
|
define_method(method) do |string|
|
||||||
end
|
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||||
|
ActiveSupport::Multibyte::Unicode##{method} is deprecated and
|
||||||
|
will be removed from Rails 6.1. Use String methods directly.
|
||||||
|
MSG
|
||||||
|
|
||||||
def upcase(string)
|
string.send(method)
|
||||||
string.upcase
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def swapcase(string)
|
|
||||||
string.swapcase
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -719,6 +719,12 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase
|
||||||
assert_equal BYTE_STRING.dup.mb_chars.class, ActiveSupport::Multibyte::Chars
|
assert_equal BYTE_STRING.dup.mb_chars.class, ActiveSupport::Multibyte::Chars
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_unicode_deprecations
|
||||||
|
assert_deprecated { ActiveSupport::Multibyte::Unicode.downcase("") }
|
||||||
|
assert_deprecated { ActiveSupport::Multibyte::Unicode.upcase("") }
|
||||||
|
assert_deprecated { ActiveSupport::Multibyte::Unicode.swapcase("") }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def string_from_classes(classes)
|
def string_from_classes(classes)
|
||||||
|
|
Loading…
Reference in a new issue