在做项目接口时,需要校验日期串的合法性,就写了这个,仅够初步使用
代码根据业务做了些限制,可去掉
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
std::string trim(const std::string& str)
{
std::string::size_type pos = str.find_first_not_of(' ');
if (pos == std::string::npos) {
return str;
}
std::string::size_type pos2 = str.find_last_not_of(' ');
if (pos2 != std::string::npos) {
return str.substr(pos, pos2 - pos + 1);
}
return str.substr(pos);
}
void split(const std::string& str, std::vector<std::string>* ret_, std::string sep = ",")
{
if (str.empty()) {
return;
}
std::string tmp;
std::string::size_type pos_begin = str.find_first_not_of(sep);
std::string::size_type comma_pos = 0;
while (pos_begin != std::string::npos) {