summaryrefslogtreecommitdiffstats
path: root/Source/cmAlgorithms.h
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-02-18 22:50:36 (GMT)
committerStephen Kelly <steveire@gmail.com>2015-02-20 20:35:58 (GMT)
commit37b88d348a20921c835ce7aa99f6db62271503a7 (patch)
tree96259ea4c15995957740dfbf421ebed066cb221f /Source/cmAlgorithms.h
parenta281809384cc19cc9a7d1726b243020b380b9395 (diff)
downloadCMake-37b88d348a20921c835ce7aa99f6db62271503a7.zip
CMake-37b88d348a20921c835ce7aa99f6db62271503a7.tar.gz
CMake-37b88d348a20921c835ce7aa99f6db62271503a7.tar.bz2
cmAlgorithms: Add cmWrap.
Port some existing cmJoin to use it. cmJoin is cumbersome to use in cases where the objective is to somehow 'quote' each item and then join it with a separator. In that case, the joiner string is harder to read and reason about. cmWrap aims to solve that. Provide an overload taking char wrappers to simplify the case of surrounding every element in quotes without needing to escape the quote character.
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r--Source/cmAlgorithms.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 8491838..43e113b 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -278,4 +278,21 @@ typename Range::const_iterator cmRemoveDuplicates(Range& r)
return cmRemoveIndices(r, indices);
}
+template<typename Range>
+std::string cmWrap(std::string prefix, Range const& r, std::string suffix,
+ std::string sep)
+{
+ if (r.empty())
+ {
+ return std::string();
+ }
+ return prefix + cmJoin(r, (suffix + sep + prefix).c_str()) + suffix;
+}
+
+template<typename Range>
+std::string cmWrap(char prefix, Range const& r, char suffix, std::string sep)
+{
+ return cmWrap(std::string(1, prefix), r, std::string(1, suffix), sep);
+}
+
#endif