46 lines
940 B
Text
46 lines
940 B
Text
import extensions;
|
|
import extensions'routines;
|
|
import system'collections;
|
|
import system'routines;
|
|
import system'text;
|
|
|
|
extension op : String
|
|
{
|
|
tokenize(separator,escape)
|
|
{
|
|
auto buffer := new TextBuilder();
|
|
auto list := new ArrayList();
|
|
|
|
bool escaping := false;
|
|
self.forEach::(ch)
|
|
{
|
|
if (escaping)
|
|
{
|
|
buffer.write(ch);
|
|
escaping := false
|
|
}
|
|
else if (ch == escape)
|
|
{
|
|
escaping := true
|
|
}
|
|
else if (ch == separator)
|
|
{
|
|
list.append(buffer.Value);
|
|
buffer.clear()
|
|
}
|
|
else
|
|
{
|
|
buffer.write(ch)
|
|
}
|
|
};
|
|
|
|
^ list
|
|
}
|
|
}
|
|
|
|
const string testcase = "one^|uno||three^^^^|four^^^|^cuatro|";
|
|
|
|
public program()
|
|
{
|
|
testcase.tokenize("|", "^").forEach(printingLn)
|
|
}
|