tt/src/string_utils.cpp

31 lines
780 B
C++

#include <string>
#include "string_utils.h"
std::string space_to_underscore(std::string str){
for(size_t i = 0; i < str.length(); i++){
if(str[i] == ' ') str[i] = '_';
}
return str;
}
std::string underscore_to_space(std::string str){
for(size_t i = 0; i < str.length(); i++){
if(str[i] == '_') str[i] = ' ';
}
return str;
}
std::string trim(const std::string& str){
const char* WhiteSpace = " ";
std::size_t start = str.find_first_not_of(WhiteSpace);
std::size_t end = str.find_last_not_of(WhiteSpace);
return start == end ? std::string() : str.substr(start, end - start + 1);
}
bool is_num(const std::string &str){
for (const char &c : str){
if (std::isdigit(c) == 0) return false;
}
return true;
}