| | |
| | | */ |
| | | |
| | | #include <cctype> //toupper |
| | | #include "StringUtils.h" |
| | | #include <iostream> |
| | | #include <string> |
| | | #include <sstream> |
| | | #include <cstring> |
| | | #include <algorithm> |
| | | #include <stdexcept> |
| | | #include <regex> |
| | | #include "StringUtils.h" |
| | | |
| | | #ifdef _WIN32 |
| | | #include <time.h> //mktime under windows |
| | |
| | | throw invalid_argument("Date not recognized"); |
| | | } |
| | | } else if (strlen(timeString) == 10) { |
| | | const int nfield = sscanf(timeString, "%4d-%2d-%2d", &year, &month, &day); |
| | | 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); |
| | | const int nfield = sscanf(timeString, "%4d/%2d/%2d", &year, &month, |
| | | &day); |
| | | if (nfield != 3) { |
| | | throw invalid_argument("Date not recognized"); |
| | | } |
| | |
| | | return mktime(&tm); |
| | | } |
| | | |
| | | |
| | | const vector<string> split_string(const string& licensePositions,char splitchar) { |
| | | const vector<string> split_string(const string &licensePositions, |
| | | char splitchar) { |
| | | std::stringstream streamToSplit(licensePositions); |
| | | std::string segment; |
| | | std::vector<string> seglist; |
| | |
| | | return seglist; |
| | | } |
| | | |
| | | const static regex iniSection("\\[.*?\\]"); |
| | | const static regex b64( |
| | | "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"); |
| | | |
| | | FILE_FORMAT identify_format(const string &license) { |
| | | FILE_FORMAT result = UNKNOWN; |
| | | if (regex_match(license, b64)) { |
| | | result = BASE64; |
| | | } else if (regex_search(license, iniSection)) { |
| | | result = INI; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | } /* namespace license */ |