MCPcopy Create free account
hub / github.com/audacity/audacity / Join

Function Join

libraries/lib-string-utils/StringUtils.h:52–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51template<template<typename, typename...> typename ContainerType, typename ResultType, typename SeparatorType, typename... Rest>
52ResultType Join(
53 const ContainerType<ResultType, Rest...>& container,
54 const SeparatorType& separator)
55{
56 if (container.empty())
57 return ResultType {};
58
59 const auto sepratorLength = StringLength(separator);
60 const auto totalSeparatorLength = sepratorLength * (container.size() - 1);
61
62 ResultType result;
63
64 const auto size = std::accumulate(
65 container.begin(), container.end(), totalSeparatorLength,
66 [](size_t size, const ResultType& item)
67 { return size + StringLength(item); });
68
69 result.reserve(size);
70
71 bool first = true;
72 for (const auto& item : container)
73 {
74 if (!first)
75 result += separator;
76 result += item;
77 first = false;
78 }
79
80 return result;
81}
82
83STRING_UTILS_API std::string ToLower(const std::string& str);
84STRING_UTILS_API std::string ToLower(const std::string_view& str);

Callers 2

Calls 5

StringLengthFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected