gcontini
2019-10-13 4e1f76fae58a7e0db111ec68e616e6ea3222f726
src/library/base/StringUtils.cpp
@@ -9,10 +9,12 @@
#include "StringUtils.h"
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <stdexcept>
#ifdef WIN32
#ifdef _WIN32
#include <time.h> //mktime under windows
#endif
@@ -41,14 +43,14 @@
   int year, month, day;
   tm tm;
   if (strlen(timeString) == 8) {
      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");
      }
   } else if (strlen(timeString) == 10) {
      int nfield = sscanf(timeString, "%4d-%2d-%2d", &year, &month, &day);
      const int nfield = sscanf(timeString, "%4d-%2d-%2d", &year, &month, &day);
      if (nfield != 3) {
         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");
         }
@@ -67,4 +69,17 @@
   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 */