MCPcopy Create free account
hub / github.com/AimRT/AimRT / SplitToSet

Function SplitToSet

src/common/util/string_util.h:280–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278 requires(std::is_same_v<StringType, std::string_view> ||
279 std::is_same_v<StringType, std::string>)
280inline std::set<StringType> SplitToSet(std::string_view source,
281 std::string_view sep,
282 bool trim = true,
283 bool clear = true) {
284 std::set<StringType> result;
285 if (source.empty() || sep.empty()) return result;
286
287 size_t pos_end = 0, pos_start = 0;
288 do {
289 pos_end = source.find(sep, pos_start);
290 if (pos_end == std::string_view::npos) pos_end = source.length();
291
292 auto sub_str = source.substr(pos_start, pos_end - pos_start);
293
294 if (trim) Trim(sub_str);
295
296 if (!(clear && sub_str.empty())) result.emplace(sub_str);
297
298 pos_start = pos_end + sep.size();
299 } while (pos_end < source.length());
300
301 return result;
302}
303
304/**
305 * @brief splicing set to string

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected