mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-21 23:03:44 +01:00
text.split[_unlimited]: Use pattern by default
This commit is contained in:
parent
1244f1eba0
commit
a5c49754d9
2
file.lua
2
file.lua
@ -19,7 +19,7 @@ end
|
||||
get_extension = split_extension
|
||||
|
||||
function split_path(filepath)
|
||||
return modlib.text.split(filepath, dir_delim)
|
||||
return modlib.text.split_unlimited(filepath, dir_delim, true)
|
||||
end
|
||||
|
||||
-- concat_path is set by init.lua to avoid code duplication
|
||||
|
@ -62,7 +62,7 @@ local warn_parent_leaf = "modlib: setting %s used both as parent setting and as
|
||||
local function build_tree(dict)
|
||||
local tree = {}
|
||||
for key, value in pairs(dict) do
|
||||
local path = modlib.text.split_unlimited(key, ".")
|
||||
local path = modlib.text.split_unlimited(key, ".", true)
|
||||
local subtree = tree
|
||||
for i = 1, #path - 1 do
|
||||
local index = tonumber(path[i]) or path[i]
|
||||
|
11
text.lua
11
text.lua
@ -45,24 +45,25 @@ function hexdump(text)
|
||||
return table.concat(dump)
|
||||
end
|
||||
|
||||
function split(text, delimiter, limit, is_regex)
|
||||
function split(text, delimiter, limit, plain)
|
||||
limit = limit or math.huge
|
||||
local no_regex = not is_regex
|
||||
local parts = {}
|
||||
local occurences = 1
|
||||
local last_index = 1
|
||||
local index = string.find(text, delimiter, 1, no_regex)
|
||||
local index = string.find(text, delimiter, 1, plain)
|
||||
while index and occurences < limit do
|
||||
table.insert(parts, string.sub(text, last_index, index - 1))
|
||||
last_index = index + string.len(delimiter)
|
||||
index = string.find(text, delimiter, index + string.len(delimiter), no_regex)
|
||||
index = string.find(text, delimiter, index + string.len(delimiter), plain)
|
||||
occurences = occurences + 1
|
||||
end
|
||||
table.insert(parts, string.sub(text, last_index))
|
||||
return parts
|
||||
end
|
||||
|
||||
function split_without_limit(text, delimiter, is_regex) return split(text, delimiter, nil, is_regex) end
|
||||
function split_without_limit(text, delimiter, plain)
|
||||
return split(text, delimiter, nil, plain)
|
||||
end
|
||||
|
||||
split_unlimited = split_without_limit
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user