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) { ZString ZString::getTokenExclude(const char *exclude) {
char previous = 0;
char *start = cursor; char *start = cursor;
while ((cursor <= (data + length)) && !isCharacter(*cursor, exclude)) do {
while ((cursor <= (data + length)) && !isCharacter(*cursor, exclude)) {
previous = *cursor;
++cursor; ++cursor;
}
++cursor;
} while(previous == '\\');
--cursor;
return ZString(start, cursor - start); return ZString(start, cursor - start);
} }

View File

@ -112,4 +112,8 @@ int main(int argc, char **argv) {
std::cout << "Trailing Zeros: " << test21.removeTrailingZeros() << std::endl; std::cout << "Trailing Zeros: " << test21.removeTrailingZeros() << std::endl;
std::cout << " " << test21 << 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;
} }