提交 4ac056c7 编写于 作者: N Norman Clarke

Use more descriptive method names

上级 a8a8dc4a
...@@ -90,7 +90,7 @@ def slice!(*args) ...@@ -90,7 +90,7 @@ def slice!(*args)
# Example: # Example:
# 'Café'.mb_chars.reverse.to_s # => 'éfaC' # 'Café'.mb_chars.reverse.to_s # => 'éfaC'
def reverse def reverse
chars(Unicode.g_unpack(@wrapped_string).reverse.flatten.pack('U*')) chars(Unicode.unpack_graphemes(@wrapped_string).reverse.flatten.pack('U*'))
end end
# Limit the byte size of the string to a number of bytes without breaking characters. Usable # Limit the byte size of the string to a number of bytes without breaking characters. Usable
...@@ -170,7 +170,7 @@ def compose ...@@ -170,7 +170,7 @@ def compose
# 'क्षि'.mb_chars.length # => 4 # 'क्षि'.mb_chars.length # => 4
# 'क्षि'.mb_chars.g_length # => 3 # 'क्षि'.mb_chars.g_length # => 3
def g_length def g_length
Unicode.g_unpack(@wrapped_string).length Unicode.unpack_graphemes(@wrapped_string).length
end end
# Replaces all ISO-8859-1 or CP1252 characters by their UTF-8 equivalent resulting in a valid UTF-8 string. # Replaces all ISO-8859-1 or CP1252 characters by their UTF-8 equivalent resulting in a valid UTF-8 string.
......
...@@ -73,9 +73,9 @@ def in_char_class?(codepoint, classes) ...@@ -73,9 +73,9 @@ def in_char_class?(codepoint, classes)
# Unpack the string at grapheme boundaries. Returns a list of character lists. # Unpack the string at grapheme boundaries. Returns a list of character lists.
# #
# Example: # Example:
# Unicode.g_unpack('क्षि') # => [[2325, 2381], [2359], [2367]] # Unicode.unpack_graphemes('क्षि') # => [[2325, 2381], [2359], [2367]]
# Unicode.g_unpack('Café') # => [[67], [97], [102], [233]] # Unicode.unpack_graphemes('Café') # => [[67], [97], [102], [233]]
def g_unpack(string) def unpack_graphemes(string)
codepoints = string.codepoints.to_a codepoints = string.codepoints.to_a
unpacked = [] unpacked = []
pos = 0 pos = 0
...@@ -105,11 +105,11 @@ def g_unpack(string) ...@@ -105,11 +105,11 @@ def g_unpack(string)
unpacked unpacked
end end
# Reverse operation of g_unpack. # Reverse operation of unpack_graphemes.
# #
# Example: # Example:
# Unicode.g_pack(Unicode.g_unpack('क्षि')) # => 'क्षि' # Unicode.pack_graphemes(Unicode.unpack_graphemes('क्षि')) # => 'क्षि'
def g_pack(unpacked) def pack_graphemes(unpacked)
unpacked.flatten.pack('U*') unpacked.flatten.pack('U*')
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册