class method
self.g_unpack
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.g_unpack(string)
Unpack the string at grapheme boundaries. Returns a list of character lists.
Example:
Chars.g_unpack('क्षि') #=> [[2325, 2381], [2359], [2367]] Chars.g_unpack('Café') #=> [[67], [97], [102], [233]]
Parameters
-
stringreq
Source
# File activesupport/lib/active_support/multibyte/chars.rb, line 493
def g_unpack(string)
codepoints = u_unpack(string)
unpacked = []
pos = 0
marker = 0
eoc = codepoints.length
while(pos < eoc)
pos += 1
previous = codepoints[pos-1]
current = codepoints[pos]
if (
# CR X LF
one = ( previous == UCD.boundary[:cr] and current == UCD.boundary[:lf] ) or
# L X (L|V|LV|LVT)
two = ( UCD.boundary[:l] === previous and in_char_class?(current, [:l,:v,:lv,:lvt]) ) or
# (LV|V) X (V|T)
three = ( in_char_class?(previous, [:lv,:v]) and in_char_class?(current, [:v,:t]) ) or
# (LVT|T) X (T)
four = ( in_char_class?(previous, [:lvt,:t]) and UCD.boundary[:t] === current ) or
# X Extend
five = (UCD.boundary[:extend] === current)
)
else
unpacked << codepoints[marker..pos-1]
marker = pos
end
end
unpacked
end
Defined in activesupport/lib/active_support/multibyte/chars.rb line 493
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Multibyte::Chars