.. _program_listing_file_Utilities_StringTools.h: Program Listing for File StringTools.h ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``Utilities/StringTools.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef __StringTools_h__ #define __StringTools_h__ #include #include #include #include #include namespace Utilities { class StringTools { public: static void tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = " ") { std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); std::string::size_type pos = str.find_first_of(delimiters, lastPos); while (std::string::npos != pos || std::string::npos != lastPos) { tokens.push_back(str.substr(lastPos, pos - lastPos)); lastPos = str.find_first_not_of(delimiters, pos); pos = str.find_first_of(delimiters, lastPos); } } template static std::string to_string_with_precision(const T val, const int n = 6) { std::ostringstream ostr; ostr.precision(n); ostr << std::fixed << val; return ostr.str(); } template static std::string real2String(const T r) { std::string str = to_string_with_precision(r,20); str.erase(str.find_last_not_of('0') + 1, std::string::npos); str.erase(str.find_last_not_of('.') + 1, std::string::npos); return str; } static std::string to_upper(const std::string& str) { std::string res = str; std::transform(res.begin(), res.end(), res.begin(), ::toupper); return res; } }; } #endif