From 8c5f749e2d9ff22e615bf34517612b01d0017482 Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:45:00 +0800 Subject: [PATCH] ADD file via upload --- src/tool.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/tool.cpp diff --git a/src/tool.cpp b/src/tool.cpp new file mode 100644 index 0000000..2659168 --- /dev/null +++ b/src/tool.cpp @@ -0,0 +1,58 @@ +#include"tool.h" +#include +#include + + +std::vectortool::split(const std::string& str){ + std::istringstream iss(str); + std::vector 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); +} \ No newline at end of file