From 6c488a934bde37ffcc1b60fa291340d0bf15efc7 Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周日, 13 10月 2019 20:02:13 +0800 Subject: [PATCH] test Linux --- src/library/base/StringUtils.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/library/base/StringUtils.cpp b/src/library/base/StringUtils.cpp index 7cd274b..3e34432 100644 --- a/src/library/base/StringUtils.cpp +++ b/src/library/base/StringUtils.cpp @@ -2,14 +2,21 @@ * StringUtils.cpp * * Created on: Apr 8, 2014 - * Author: devel + * */ #include <cctype> //toupper #include "StringUtils.h" #include <iostream> #include <string> +#include <sstream> +#include <cstring> #include <algorithm> +#include <stdexcept> + +#ifdef _WIN32 +#include <time.h> //mktime under windows +#endif namespace license { using namespace std; @@ -28,8 +35,51 @@ string toupper_copy(const string& lowercase) { string cp(lowercase); - std::transform(cp.begin(), cp.end(), cp.begin(), (int(*)(int))toupper); + std::transform(cp.begin(), cp.end(), cp.begin(), (int (*)(int))toupper); return cp; } +time_t seconds_from_epoch(const char* timeString) { + int year, month, day; + tm tm; + if (strlen(timeString) == 8) { + const int nfield = sscanf(timeString, "%4d%2d%2d", &year, &month, &day); + if (nfield != 3) { + throw invalid_argument("Date not recognized"); + } + } else if (strlen(timeString) == 10) { + const int nfield = sscanf(timeString, "%4d-%2d-%2d", &year, &month, &day); + if (nfield != 3) { + const int nfield = sscanf(timeString, "%4d/%2d/%2d", &year, &month, &day); + if (nfield != 3) { + throw invalid_argument("Date not recognized"); + } + } + } else{ + throw invalid_argument("Date not recognized"); + } + tm.tm_isdst = -1; + tm.tm_year = year - 1900; + tm.tm_mon = month - 1; + tm.tm_mday = day; + tm.tm_hour = 0; + tm.tm_min = 0; + tm.tm_sec = 0; + tm.tm_yday = -1; + tm.tm_wday = -1; + return mktime(&tm); +} + + +const vector<string> split_string(const string& licensePositions,char splitchar) { + std::stringstream streamToSplit(licensePositions); + std::string segment; + std::vector<string> seglist; + + while (std::getline(streamToSplit, segment, splitchar)) { + seglist.push_back(segment); + } + return seglist; +} + } /* namespace license */ -- Gitblit v1.9.1