mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
StringJoin can take a separator.
This commit is contained in:
parent
3132572e72
commit
3058e15460
11
src/utils.h
11
src/utils.h
@ -49,12 +49,14 @@ std::vector<std::string> SplitString(const std::string& str,
|
||||
std::string LowerPathIfCaseInsensitive(const std::string& path);
|
||||
|
||||
template <typename TValues, typename TMap>
|
||||
std::string StringJoinMap(const TValues& values, const TMap& map) {
|
||||
std::string StringJoinMap(const TValues& values,
|
||||
const TMap& map,
|
||||
const std::string& sep = ", ") {
|
||||
std::string result;
|
||||
bool first = true;
|
||||
for (auto& entry : values) {
|
||||
if (!first)
|
||||
result += ", ";
|
||||
result += sep;
|
||||
first = false;
|
||||
result += map(entry);
|
||||
}
|
||||
@ -62,8 +64,9 @@ std::string StringJoinMap(const TValues& values, const TMap& map) {
|
||||
}
|
||||
|
||||
template <typename TValues>
|
||||
std::string StringJoin(const TValues& values) {
|
||||
return StringJoinMap(values, [](const std::string& entry) { return entry; });
|
||||
std::string StringJoin(const TValues& values, const std::string& sep = ", ") {
|
||||
return StringJoinMap(values, [](const std::string& entry) { return entry; },
|
||||
sep);
|
||||
}
|
||||
|
||||
template <typename TCollection, typename TValue>
|
||||
|
Loading…
Reference in New Issue
Block a user