27 lines
764 B
Text
27 lines
764 B
Text
tokenize = iter (sep, esc: char, s: string) yields (string)
|
|
escape: bool := false
|
|
part: array[char] := array[char]$[]
|
|
for c: char in string$chars(s) do
|
|
if escape then
|
|
escape := false
|
|
array[char]$addh(part,c)
|
|
elseif c=esc then
|
|
escape := true
|
|
elseif c=sep then
|
|
yield(string$ac2s(part))
|
|
part := array[char]$[]
|
|
else
|
|
array[char]$addh(part,c)
|
|
end
|
|
end
|
|
yield(string$ac2s(part))
|
|
end tokenize
|
|
|
|
start_up = proc ()
|
|
po: stream := stream$primary_output()
|
|
testcase: string := "one^|uno||three^^^^|four^^^|^quatro|"
|
|
|
|
for part: string in tokenize('|', '^', testcase) do
|
|
stream$putl(po, "\"" || part || "\"")
|
|
end
|
|
end start_up
|