utility.hpp (736B)
1 #pragma once 2 3 #include <algorithm> 4 #include <string> 5 6 inline std::string& ltrim(std::string& str) 7 { 8 str.erase( 9 str.begin(), 10 std::find_if(str.begin(), 11 str.end(), 12 [](unsigned char chr) { return std::isspace(chr) == 0; })); 13 return str; 14 } 15 16 inline std::string& rtrim(std::string& str) 17 { 18 str.erase( 19 std::find_if(str.rbegin(), 20 str.rend(), 21 [](unsigned char chr) { return std::isspace(chr) == 0; }) 22 .base(), 23 str.end()); 24 return str; 25 } 26 27 inline std::string& trim(std::string& str) 28 { 29 return rtrim(ltrim(str)); 30 } 31 32 inline std::string& normalize(std::string& str) 33 { 34 std::replace(str.begin(), str.end(), ' ', '_'); 35 return str; 36 }