parent
f8e40c1151
commit
8c5f749e2d
@ -0,0 +1,58 @@
|
||||
#include"tool.h"
|
||||
#include<sstream>
|
||||
#include<ctime>
|
||||
|
||||
|
||||
std::vector<std::string>tool::split(const std::string& str){
|
||||
std::istringstream iss(str);
|
||||
std::vector<std::string> tokens;
|
||||
std::string token;
|
||||
std::istringstream tokenStream(str);
|
||||
|
||||
while(std::getline(tokenStream,token,' ')){
|
||||
tokens.push_back(token);
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
bool tool::isNumber(const std::string& str){
|
||||
if(str.empty()){
|
||||
return false;
|
||||
}
|
||||
|
||||
int start = 0;
|
||||
if(str[0] == '-'){
|
||||
if(str.size() == 1){
|
||||
return false;
|
||||
}
|
||||
start = 1;
|
||||
}
|
||||
|
||||
for(int i = start;i < str.size();i++){
|
||||
if(!isdigit(str[i])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string tool::getCurrentTime(){
|
||||
time_t now = time(0);
|
||||
tm* ltm = localtime(&now);
|
||||
char buffer[80];
|
||||
strftime(buffer,80,"%Y-%m-%d-%H-%M-%S",ltm);
|
||||
std::string nowTime = buffer;
|
||||
return nowTime;
|
||||
}
|
||||
|
||||
std::string tool::EreaseEmpty(const std::string& question){
|
||||
int start = question.find_first_not_of("\t\n\r");
|
||||
int end = question.find_last_not_of("\t\n\r");
|
||||
if(start == std::string::npos||end == std::string::npos){
|
||||
return "";
|
||||
}
|
||||
|
||||
return question.substr(start,end - start + 1);
|
||||
}
|
||||
Loading…
Reference in new issue