| | |
| | | return cp; |
| | | } |
| | | |
| | | time_t seconds_from_epoch(const char *timeString) { |
| | | time_t seconds_from_epoch(const string &timeString) { |
| | | int year, month, day; |
| | | tm tm; |
| | | if (strlen(timeString) == 8) { |
| | | const int nfield = sscanf(timeString, "%4d%2d%2d", &year, &month, &day); |
| | | if (timeString.size() == 8) { |
| | | const int nfield = sscanf(timeString.c_str(), "%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); |
| | | } else if (timeString.size() == 10) { |
| | | const int nfield = sscanf(timeString.c_str(), "%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.c_str(), "%4d/%2d/%2d", &year, &month, &day); |
| | | if (nfield != 3) { |
| | | throw invalid_argument("Date not recognized"); |
| | | throw invalid_argument("Date [" + timeString + "] not recognized"); |
| | | } |
| | | } |
| | | } else { |
| | | throw invalid_argument("Date not recognized"); |
| | | throw invalid_argument("Date [" + timeString + "] not recognized"); |
| | | } |
| | | tm.tm_isdst = -1; |
| | | tm.tm_year = year - 1900; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | const static regex iniSection("\\[.*?\\]"); |
| | | const static regex b64( |
| | | "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"); |
| | | 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; |
| | |
| | | return result; |
| | | } |
| | | |
| | | // strnln_s is not well supported and strlen is marked unsafe.. |
| | | size_t mstrnlen_s(const char *szptr, size_t maxsize) { |
| | | if (szptr == nullptr) { |
| | | return 0; |
| | | } |
| | | size_t count = 0; |
| | | while (*szptr++ && maxsize--) { |
| | | count++; |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | } /* namespace license */ |