20 lines
529 B
Text
20 lines
529 B
Text
F token_with_escape(a, escape = ‘^’, separator = ‘|’)
|
||
[String] result
|
||
V token = ‘’
|
||
V state = 0
|
||
L(c) a
|
||
I state == 0
|
||
I c == escape
|
||
state = 1
|
||
E I c == separator
|
||
result.append(token)
|
||
token = ‘’
|
||
E
|
||
token ‘’= c
|
||
E I state == 1
|
||
token ‘’= c
|
||
state = 0
|
||
result.append(token)
|
||
R result
|
||
|
||
print(token_with_escape(‘one^|uno||three^^^^|four^^^|^cuatro|’).map(s -> ‘'’s‘'’).join(‘, ’))
|