diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-07-29 15:34:54 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-08-01 09:45:04 (GMT) |
commit | e5d3ea22d49e6d85082306d1f73d0689a3fbca81 (patch) | |
tree | 49cb6cfcea887454bddab8e6cc79883a3351139d /Source/cmStringAlgorithms.h | |
parent | a7d0fe9c24e111bc4f325d608b31fdf394c24602 (diff) | |
download | CMake-e5d3ea22d49e6d85082306d1f73d0689a3fbca81.zip CMake-e5d3ea22d49e6d85082306d1f73d0689a3fbca81.tar.gz CMake-e5d3ea22d49e6d85082306d1f73d0689a3fbca81.tar.bz2 |
cmStringAlgorithms: Add cmCatViews and cmStrCat functions
Diffstat (limited to 'Source/cmStringAlgorithms.h')
-rw-r--r-- | Source/cmStringAlgorithms.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 8d6aec6..3037bef 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -7,6 +7,7 @@ #include "cmRange.h" #include "cm_string_view.hxx" +#include <initializer_list> #include <sstream> #include <string.h> #include <string> @@ -48,6 +49,55 @@ std::string cmJoin(Range const& rng, cm::string_view separator) return os.str(); } +/** Concatenate string pieces into a single string. */ +std::string cmCatViews(std::initializer_list<cm::string_view> views); + +/** Utility class for cmStrCat. */ +class cmAlphaNum +{ +public: + cmAlphaNum(cm::string_view view) + : View_(view) + { + } + cmAlphaNum(std::string const& str) + : View_(str) + { + } + cmAlphaNum(const char* str) + : View_(str) + { + } + cmAlphaNum(char ch) + : View_(Digits_, 1) + { + Digits_[0] = ch; + } + cmAlphaNum(int val); + cmAlphaNum(unsigned int val); + cmAlphaNum(long int val); + cmAlphaNum(unsigned long int val); + cmAlphaNum(long long int val); + cmAlphaNum(unsigned long long int val); + cmAlphaNum(float val); + cmAlphaNum(double val); + + cm::string_view View() const { return View_; } + +private: + cm::string_view View_; + char Digits_[32]; +}; + +/** Concatenate string pieces and numbers into a single string. */ +template <typename... AV> +inline std::string cmStrCat(cmAlphaNum const& a, cmAlphaNum const& b, + AV const&... args) +{ + return cmCatViews( + { a.View(), b.View(), static_cast<cmAlphaNum const&>(args).View()... }); +} + template <typename Range> std::string cmWrap(std::string const& prefix, Range const& r, std::string const& suffix, std::string const& sep) |