mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-18 06:31:15 +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);
|
std::string LowerPathIfCaseInsensitive(const std::string& path);
|
||||||
|
|
||||||
template <typename TValues, typename TMap>
|
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;
|
std::string result;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& entry : values) {
|
for (auto& entry : values) {
|
||||||
if (!first)
|
if (!first)
|
||||||
result += ", ";
|
result += sep;
|
||||||
first = false;
|
first = false;
|
||||||
result += map(entry);
|
result += map(entry);
|
||||||
}
|
}
|
||||||
@ -62,8 +64,9 @@ std::string StringJoinMap(const TValues& values, const TMap& map) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename TValues>
|
template <typename TValues>
|
||||||
std::string StringJoin(const TValues& values) {
|
std::string StringJoin(const TValues& values, const std::string& sep = ", ") {
|
||||||
return StringJoinMap(values, [](const std::string& entry) { return entry; });
|
return StringJoinMap(values, [](const std::string& entry) { return entry; },
|
||||||
|
sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TCollection, typename TValue>
|
template <typename TCollection, typename TValue>
|
||||||
|
Loading…
Reference in New Issue
Block a user