mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Deprecate Unicode's #pack_graphemes and #unpack_graphemes methods
in favor of `array.flatten.pack("U*")` and `string.scan(/\X/).map(&:codepoints)`, respectively.
This commit is contained in:
parent
885ab065b5
commit
b0f3070209
3 changed files with 21 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
* Deprecate `ActiveSupport::Multibyte::Unicode#pack_graphemes(array)` and `ActiveSuppport::Multibyte::Unicode#unpack_graphemes(string)`
|
||||||
|
in favor of `array.flatten.pack("U*")` and `string.scan(/\X/).map(&:codepoints)`, respectively.
|
||||||
|
|
||||||
|
*Francesco Rodríguez*
|
||||||
|
|
||||||
* Deprecate `ActiveSupport::Multibyte::Chars.consumes?` in favor of `String#is_utf8?`.
|
* Deprecate `ActiveSupport::Multibyte::Chars.consumes?` in favor of `String#is_utf8?`.
|
||||||
|
|
||||||
*Francesco Rodríguez*
|
*Francesco Rodríguez*
|
||||||
|
|
|
@ -34,6 +34,11 @@ module ActiveSupport
|
||||||
# Unicode.unpack_graphemes('क्षि') # => [[2325, 2381], [2359], [2367]]
|
# Unicode.unpack_graphemes('क्षि') # => [[2325, 2381], [2359], [2367]]
|
||||||
# Unicode.unpack_graphemes('Café') # => [[67], [97], [102], [233]]
|
# Unicode.unpack_graphemes('Café') # => [[67], [97], [102], [233]]
|
||||||
def unpack_graphemes(string)
|
def unpack_graphemes(string)
|
||||||
|
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||||
|
ActiveSupport::Multibyte::Unicode#unpack_graphemes is deprecated and will be
|
||||||
|
removed from Rails 6.1. Use string.scan(/\X/).map(&:codepoints) instead.
|
||||||
|
MSG
|
||||||
|
|
||||||
string.scan(/\X/).map(&:codepoints)
|
string.scan(/\X/).map(&:codepoints)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,6 +46,11 @@ module ActiveSupport
|
||||||
#
|
#
|
||||||
# Unicode.pack_graphemes(Unicode.unpack_graphemes('क्षि')) # => 'क्षि'
|
# Unicode.pack_graphemes(Unicode.unpack_graphemes('क्षि')) # => 'क्षि'
|
||||||
def pack_graphemes(unpacked)
|
def pack_graphemes(unpacked)
|
||||||
|
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||||
|
ActiveSupport::Multibyte::Unicode#pack_graphemes is deprecated and will be
|
||||||
|
removed from Rails 6.1. Use array.flatten.pack("U*") instead.
|
||||||
|
MSG
|
||||||
|
|
||||||
unpacked.flatten.pack("U*")
|
unpacked.flatten.pack("U*")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,12 @@ class MultibyteGraphemeBreakConformanceTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_breaks
|
def test_breaks
|
||||||
each_line_of_break_tests do |*cols|
|
ActiveSupport::Deprecation.silence do
|
||||||
*clusters, comment = *cols
|
each_line_of_break_tests do |*cols|
|
||||||
packed = ActiveSupport::Multibyte::Unicode.pack_graphemes(clusters)
|
*clusters, comment = *cols
|
||||||
assert_equal clusters, ActiveSupport::Multibyte::Unicode.unpack_graphemes(packed), comment
|
packed = ActiveSupport::Multibyte::Unicode.pack_graphemes(clusters)
|
||||||
|
assert_equal clusters, ActiveSupport::Multibyte::Unicode.unpack_graphemes(packed), comment
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue