This shows different approaches for string parsing.
- Whitespace
Many Evo methods skip or strip whitespace. This may or may not include newlines – this will be noted in the method documentation.
- Newlines are often used to define structure with plain text so it doesn't always make sense to skip them
- When performance is critical, code that only skips spaces and tabs is generally faster than a version that also skips newlines (even with SSE optimization)
- Tokenizers usually don't skip newlines
- Methods like String::strip() have a variant like String::strip2() that also strips newlines
- Check Null or Empty
int main() {
{ }
{ }
{ }
return 0;
}
- Splitting
Splitting to substrings:
int main() {
String str(
"foo=bar"), left, right;
str.
split(
'=', left, right);
return 0;
}
Splitting to a list with generic conversion:
Splitting to a list with generic conversion and alternate tokenizer:
- Tokenizing
String and SubString have methods for extracting tokens:
int main() {
while (str.
token(value,
','))
return 0;
}
StrTok classes can parse into substring tokens:
int main() {
while (tok1.next(','))
c.
out << tok1.value() <<
NL;
while (tok2.next(','))
c.
out << tok2.value() <<
NL;
StrTokQ tok3(
"one,'two,two',three");
while (tok3.next(','))
c.
out << tok3.value() <<
NL;
StrTok tok4(
"one,'two,two',three");
while (tok4.nextq(','))
c.
out << tok4.value() <<
NL;
return 0;
}
- Quoting
StrTokQ and StrTok::nextq() can parse quoted tokens.
See Smart Quoting
- Low-Level Scanning