diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-07-31 20:07:05 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-08-01 09:45:04 (GMT) |
commit | 75cf7ec263034e0212554f373bb6fd02d351163f (patch) | |
tree | 82072e0c19f8dbb1ac29635e66a125b700eac048 /Source/cmStringAlgorithms.h | |
parent | e5d3ea22d49e6d85082306d1f73d0689a3fbca81 (diff) | |
download | CMake-75cf7ec263034e0212554f373bb6fd02d351163f.zip CMake-75cf7ec263034e0212554f373bb6fd02d351163f.tar.gz CMake-75cf7ec263034e0212554f373bb6fd02d351163f.tar.bz2 |
cmStringAlgorithms: Modernize cmWrap using cm::string_view
Diffstat (limited to 'Source/cmStringAlgorithms.h')
-rw-r--r-- | Source/cmStringAlgorithms.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 3037bef..cdb494f 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -98,21 +98,25 @@ inline std::string cmStrCat(cmAlphaNum const& a, cmAlphaNum const& b, { a.View(), b.View(), static_cast<cmAlphaNum const&>(args).View()... }); } +/** Joins wrapped elements of a range with separator into a single string. */ template <typename Range> -std::string cmWrap(std::string const& prefix, Range const& r, - std::string const& suffix, std::string const& sep) +std::string cmWrap(cm::string_view prefix, Range const& rng, + cm::string_view suffix, cm::string_view sep) { - if (r.empty()) { + if (rng.empty()) { return std::string(); } - return prefix + cmJoin(r, suffix + sep + prefix) + suffix; + return cmCatViews( + { prefix, cmJoin(rng, cmCatViews({ suffix, sep, prefix })), suffix }); } +/** Joins wrapped elements of a range with separator into a single string. */ template <typename Range> -std::string cmWrap(char prefix, Range const& r, char suffix, - std::string const& sep) +std::string cmWrap(char prefix, Range const& rng, char suffix, + cm::string_view sep) { - return cmWrap(std::string(1, prefix), r, std::string(1, suffix), sep); + return cmWrap(cm::string_view(&prefix, 1), rng, cm::string_view(&suffix, 1), + sep); } /** Returns true if string @a str starts with the character @a prefix. */ |