diff --git a/dune/xt/common/string.cc b/dune/xt/common/string.cc index c4d2b145303c7257ea6f0f7c1a659b303658048d..ea3b4aef121691302763730ef115cd104f535069 100644 --- a/dune/xt/common/string.cc +++ b/dune/xt/common/string.cc @@ -13,6 +13,7 @@ #include <algorithm> #include <cctype> #include <string> +#include <sstream> #include "string.hh" @@ -37,6 +38,19 @@ std::string to_upper(const std::string& ss) } +std::string to_camel_case(const std::string& ss) +{ + std::stringstream out; + for (auto&& word : tokenize(ss, "_", boost::algorithm::token_compress_on)) { + if (word.size() > 0) { + out << to_upper(word.substr(0, 1)); + out << word.substr(1); + } + } + return out.str(); +} + + } // namespace Common } // namespace XT } // namespace Dune diff --git a/dune/xt/common/string.hh b/dune/xt/common/string.hh index 570a22deecf5a61e3d204c42669cd60717237f01..d861fcbcb2cbabbc65ae42203ae271acd20ad382 100644 --- a/dune/xt/common/string.hh +++ b/dune/xt/common/string.hh @@ -128,6 +128,12 @@ std::string to_lower(const std::string& ss); std::string to_upper(const std::string& ss); +/** + * \brief Converts this_sample_string to ThisSampleString. + */ +std::string to_camel_case(const std::string& ss); + + /** \brief Returns a string of lengths t' whitespace (or whitespace chars). \param[in] t defines the length of the return string (after conversion to string)