mirror of
https://github.com/hkalexling/Mango.git
synced 2026-04-30 00:00:43 -04:00
Simplify the split_by_alphanumeric function
This commit is contained in:
+3
-22
@@ -38,29 +38,10 @@ def is_numeric(str)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def split_by_alphanumeric(str)
|
def split_by_alphanumeric(str)
|
||||||
is_number = false
|
|
||||||
arr = [] of String
|
arr = [] of String
|
||||||
arr.push(
|
str.scan(/([^\d\n\r]*)(\d*)([^\d\n\r]*)/) do |match|
|
||||||
str.split("").reduce("") do |memo, c|
|
arr += match.captures.select{|s| s != ""}
|
||||||
if (is_number)
|
end
|
||||||
if is_numeric(c)
|
|
||||||
memo + c
|
|
||||||
else
|
|
||||||
arr.push(memo) if memo != ""
|
|
||||||
is_number = false
|
|
||||||
c
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if is_numeric(c) # number
|
|
||||||
arr.push(memo) if memo != ""
|
|
||||||
is_number = true
|
|
||||||
c
|
|
||||||
else
|
|
||||||
memo + c
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
arr
|
arr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user