2025-06-11 20:16:52 -04:00
|
|
|
function Tokenize (str, sep, esc)
|
2023-07-01 11:58:00 -04:00
|
|
|
local strList, word, escaped, ch = {}, "", false
|
|
|
|
|
for pos = 1, #str do
|
|
|
|
|
ch = str:sub(pos, pos)
|
|
|
|
|
if ch == esc then
|
|
|
|
|
if escaped then
|
|
|
|
|
word = word .. ch
|
|
|
|
|
end
|
2025-06-11 20:16:52 -04:00
|
|
|
escaped = not escaped
|
2023-07-01 11:58:00 -04:00
|
|
|
elseif ch == sep then
|
|
|
|
|
if escaped then
|
|
|
|
|
word = word .. ch
|
|
|
|
|
escaped = false
|
|
|
|
|
else
|
|
|
|
|
table.insert(strList, word)
|
|
|
|
|
word = ""
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
escaped = false
|
|
|
|
|
word = word .. ch
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
table.insert(strList, word)
|
|
|
|
|
return strList
|
|
|
|
|
end
|