Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
func String.Tokenize(separator, escape) {
|
||||
var buffer = []
|
||||
var escaping = false
|
||||
for c in this {
|
||||
if escaping {
|
||||
buffer.Add(c)
|
||||
escaping = false
|
||||
} else if c == escape {
|
||||
escaping = true
|
||||
} else if c == separator {
|
||||
yield buffer.Flush();
|
||||
} else {
|
||||
buffer.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
if buffer.Length() > 0 || this[this.Length() - 1] == separator {
|
||||
yield buffer.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func Array.Flush() {
|
||||
var str = String.Concat(values: this)
|
||||
this.Clear()
|
||||
str
|
||||
}
|
||||
|
||||
let testcase = "one^|uno||three^^^^|four^^^|^cuatro|";
|
||||
for token in testcase.Tokenize(separator: '|', escape: '^') {
|
||||
print(": \(token)")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue