changed getTokenExclude method to allow escaped characters.

This commit is contained in:
Brad Arant 2024-11-14 09:44:12 -08:00
parent c70f135710
commit 8f5dd52c6a
2 changed files with 13 additions and 2 deletions

View File

@ -291,9 +291,16 @@ namespace coreutils {
}
ZString ZString::getTokenExclude(const char *exclude) {
char previous = 0;
char *start = cursor;
while ((cursor <= (data + length)) && !isCharacter(*cursor, exclude))
++cursor;
do {
while ((cursor <= (data + length)) && !isCharacter(*cursor, exclude)) {
previous = *cursor;
++cursor;
}
++cursor;
} while(previous == '\\');
--cursor;
return ZString(start, cursor - start);
}

View File

@ -111,5 +111,9 @@ int main(int argc, char **argv) {
coreutils::ZString test21("10.00000000");
std::cout << "Trailing Zeros: " << test21.removeTrailingZeros() << std::endl;
std::cout << " " << test21 << std::endl;
coreutils::ZString test22("This is a \\\"quoted\\\" string.\"");
std::cout << "quoted string: " << test22 << std::endl;
std::cout << "quoted string: " << test22.getTokenExclude("\"") << std::endl;
}