From 40e231bc29e453ecb685b02204cec46c458b80d7 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 24 Jan 2015 09:39:14 +0100 Subject: StringUtils: Added string vector manipulation. --- src/StringUtils.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index a63525356..48486a762 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -905,3 +905,47 @@ bool SplitZeroTerminatedStrings(const AString & a_Strings, AStringVector & a_Out + +AStringVector MergeStringVectors(const AStringVector & a_Strings1, const AStringVector & a_Strings2) +{ + // Initialize the resulting vector by the first vector: + AStringVector res = a_Strings1; + + // Add each item from strings2 that is not already present: + for (auto item : a_Strings2) + { + if (std::find(res.begin(), res.end(), item) != res.end()) + { + res.push_back(item); + } + } // for item - a_Strings2[] + + return res; +} + + + + + +AString StringsConcat(const AStringVector & a_Strings, char a_Separator) +{ + // If the vector is empty, return an empty string: + if (a_Strings.empty()) + { + return ""; + } + + // Concatenate the strings in the vector: + AString res; + res.append(a_Strings[0]); + for (auto itr = a_Strings.cbegin() + 1, end = a_Strings.cend(); itr != end; ++itr) + { + res.push_back(a_Separator); + res.append(*itr); + } + return res; +} + + + + -- cgit v1.2.3 From 7cff25f0ffa70bf142663ccdc320bf86dfb623dd Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 24 Jan 2015 15:58:40 +0100 Subject: StringUtils: Fixed bad predicate in MergeStringVectors(). Instead of preventing duplicates it was allowing only duplicates. --- src/StringUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 48486a762..4eb2d48b6 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -914,7 +914,7 @@ AStringVector MergeStringVectors(const AStringVector & a_Strings1, const AString // Add each item from strings2 that is not already present: for (auto item : a_Strings2) { - if (std::find(res.begin(), res.end(), item) != res.end()) + if (std::find(res.begin(), res.end(), item) == res.end()) { res.push_back(item); } -- cgit v1.2.3