From 6544f40295e93fbb8d25582bd3a94341537ec6ca Mon Sep 17 00:00:00 2001 From: David Monahan Date: Wed, 22 Apr 2020 11:28:23 +0100 Subject: IVGCVSW-4718 Fix failing Execute Network Tests * Fix for StringTokenizer utility method to match Boost::Split implementation Signed-off-by: David Monahan Change-Id: I50e047ff72191da9aa06b71370c4354c5a78eb9b --- include/armnn/utility/StringUtils.hpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/armnn/utility/StringUtils.hpp b/include/armnn/utility/StringUtils.hpp index c56a215b83..cc5e8e7349 100644 --- a/include/armnn/utility/StringUtils.hpp +++ b/include/armnn/utility/StringUtils.hpp @@ -16,38 +16,38 @@ namespace stringUtils /// Function to take a string and a list of delimiters and split the string into tokens based on those delimiters /// This assumes that tokens are also to be split by newlines -/// Enabling token compression causes this to ignore multiple concurrent delimiters +/// Enabling tokenCompression merges adjacent delimiters together, preventing empty tokens inline std::vector StringTokenizer(const std::string& str, const char* delimiters, bool tokenCompression = true) { std::stringstream stringStream(str); std::string line; - std::vector wordVector; + std::vector tokenVector; while (std::getline(stringStream, line)) { std::size_t prev = 0; std::size_t pos; while ((pos = line.find_first_of(delimiters, prev)) != std::string::npos) { + // Ignore adjacent tokens if (pos > prev) { - // If token compression is enabled ignore delimiters that are next to each other - if (tokenCompression && (pos - prev == 1)) - { - prev = pos + 1; - continue; - } - wordVector.push_back(line.substr(prev, pos - prev)); + tokenVector.push_back(line.substr(prev, pos - prev)); + } + // Unless token compression is disabled + else if (!tokenCompression) + { + tokenVector.push_back(line.substr(prev, pos - prev)); } prev = pos + 1; } if (prev < line.length()) { - wordVector.push_back(line.substr(prev, std::string::npos)); + tokenVector.push_back(line.substr(prev, std::string::npos)); } } - return wordVector; + return tokenVector; } // Set of 3 utility functions for trimming std::strings -- cgit v1.2.1