diff options
| author | Stefan Boberg <[email protected]> | 2021-09-17 19:11:27 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-17 19:11:27 +0200 |
| commit | a47396e06a8c6ebc2a44135c47d4820e6984c225 (patch) | |
| tree | e719ed435a2de51e477822d98b0c71083edcca6a /zencore/string.cpp | |
| parent | Implemented basics for Windows server support (not yet 100% - needs to proper... (diff) | |
| parent | Added upstream cache policy command line option (read|write,readonly,writeonl... (diff) | |
| download | zen-a47396e06a8c6ebc2a44135c47d4820e6984c225.tar.xz zen-a47396e06a8c6ebc2a44135c47d4820e6984c225.zip | |
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zencore/string.cpp')
| -rw-r--r-- | zencore/string.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/zencore/string.cpp b/zencore/string.cpp index 8ea10d2a3..ce1b6d675 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -912,4 +912,44 @@ TEST_CASE("filepath") CHECK(FilepathFindExtension(".txt") == std::string_view(".txt")); } +TEST_CASE("string") +{ + using namespace std::literals; + + SUBCASE("ForEachStrTok") + { + const auto Tokens = "here,is,my,different,tokens"sv; + int32_t ExpectedTokenCount = 5; + int32_t TokenCount = 0; + StringBuilder<512> Sb; + + TokenCount = ForEachStrTok(Tokens, ',', [&Sb](const std::string_view& Token) { + if (Sb.Size()) + { + Sb << ","; + } + Sb << Token; + return true; + }); + + CHECK(TokenCount == ExpectedTokenCount); + CHECK(Sb.ToString() == Tokens); + + ExpectedTokenCount = 1; + const auto Str = "mosdef"sv; + + Sb.Reset(); + TokenCount = ForEachStrTok(Str, ' ', [&Sb](const std::string_view& Token) { + Sb << Token; + return true; + }); + CHECK(Sb.ToString() == Str); + CHECK(TokenCount == ExpectedTokenCount); + + ExpectedTokenCount = 0; + TokenCount = ForEachStrTok(""sv, ',', [](const std::string_view&) { return true; }); + CHECK(TokenCount == ExpectedTokenCount); + } +} + } // namespace zen |