From 8f5dd52c6ad001e9c79f9a5c6249f674b599552e Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Thu, 14 Nov 2024 09:44:12 -0800 Subject: [PATCH] changed getTokenExclude method to allow escaped characters. --- ZString.cpp | 11 +++++++++-- testing/zstring_test.cpp | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ZString.cpp b/ZString.cpp index 9585b6f..668c195 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -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); } diff --git a/testing/zstring_test.cpp b/testing/zstring_test.cpp index b568634..c76b329 100644 --- a/testing/zstring_test.cpp +++ b/testing/zstring_test.cpp @@ -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; }