Upgrade from Wt3 to Wt4
This commit is contained in:
@@ -19,12 +19,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WServer>
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WLogger>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <Wt/WApplication.h>
|
||||
#include <Wt/WLogger.h>
|
||||
|
||||
enum class Severity
|
||||
{
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ void computeCrc(const boost::filesystem::path& p, std::vector<unsigned char>& cr
|
||||
}
|
||||
else
|
||||
{
|
||||
LMS_LOG(DBUPDATER, ERROR) << "Failed to open file '" << p << "'";
|
||||
LMS_LOG(DBUPDATER, ERROR) << "Failed to open file '" << p.string() << "'";
|
||||
throw std::runtime_error("Failed to open file '" + p.string() + "'" );
|
||||
}
|
||||
|
||||
|
||||
+20
-41
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
@@ -26,42 +27,28 @@
|
||||
|
||||
#include "Utils.hpp"
|
||||
|
||||
|
||||
boost::optional<long>
|
||||
readLong(const std::string& str)
|
||||
template<>
|
||||
boost::optional<Wt::WDate> readAs(const std::string& str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::stol(str);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
return boost::none;
|
||||
}
|
||||
}
|
||||
|
||||
bool readAsPosixTime(const std::string& str, boost::posix_time::ptime& time)
|
||||
{
|
||||
const std::locale formats[] = {
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%m-%d")),
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%b-%d")),
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%B-%d")),
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y/%m/%d")),
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%d.%m.%Y")),
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%m")),
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y/%m")),
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y.%m")),
|
||||
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y")),
|
||||
const std::vector<std::string> formats = {
|
||||
"yyyy-MM-dd",
|
||||
"yyyy/MM/dd",
|
||||
"yyyy-MM",
|
||||
"yyyy/MM",
|
||||
"yyyy"
|
||||
};
|
||||
for(size_t i=0; i < sizeof(formats)/sizeof(formats[0]); ++i)
|
||||
|
||||
for (auto format : formats)
|
||||
{
|
||||
std::istringstream iss(str);
|
||||
iss.imbue(formats[i]);
|
||||
if (iss >> time)
|
||||
return true;
|
||||
auto date = Wt::WDate::fromString(str, format);
|
||||
|
||||
if (!date.isValid())
|
||||
continue;
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
return false;
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
bool readList(const std::string& str, const std::string& separators, std::list<std::string>& results)
|
||||
@@ -72,7 +59,7 @@ bool readList(const std::string& str, const std::string& separators, std::list<s
|
||||
{
|
||||
if (separators.find(c) != std::string::npos) {
|
||||
if (!curStr.empty()) {
|
||||
results.push_back(stringToUTF8(curStr));
|
||||
results.push_back(curStr);
|
||||
curStr.clear();
|
||||
}
|
||||
}
|
||||
@@ -85,7 +72,7 @@ bool readList(const std::string& str, const std::string& separators, std::list<s
|
||||
}
|
||||
|
||||
if (!curStr.empty())
|
||||
results.push_back(stringToUTF8(curStr));
|
||||
results.push_back(curStr);
|
||||
|
||||
return !str.empty();
|
||||
}
|
||||
@@ -131,14 +118,6 @@ stringTrimEnd(const std::string& str, const std::string& whitespace)
|
||||
return str.substr(0, str.find_last_not_of(whitespace)+1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string
|
||||
stringToUTF8(const std::string& str)
|
||||
{
|
||||
return boost::locale::conv::to_utf<char>(str, "UTF-8");
|
||||
}
|
||||
|
||||
std::string
|
||||
bufferToString(const std::vector<unsigned char>& data)
|
||||
{
|
||||
|
||||
+19
-18
@@ -19,26 +19,21 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
|
||||
|
||||
boost::optional<long>
|
||||
readLong(const std::string& str);
|
||||
|
||||
bool
|
||||
readAsPosixTime(const std::string& str, boost::posix_time::ptime& time);
|
||||
#include <Wt/WDate.h>
|
||||
|
||||
bool
|
||||
readList(const std::string& str, const std::string& separators, std::list<std::string>& results);
|
||||
|
||||
std::string
|
||||
durationToString(boost::posix_time::time_duration duration, std::string format);
|
||||
//std::string
|
||||
//durationToString(boost::posix_time::time_duration duration, std::string format);
|
||||
|
||||
std::vector<std::string>
|
||||
splitString(std::string string, std::string separators);
|
||||
@@ -49,17 +44,23 @@ stringTrim(const std::string& str, const std::string& whitespaces = " \t");
|
||||
std::string
|
||||
stringTrimEnd(const std::string& str, const std::string& whitespaces = " \t");
|
||||
|
||||
std::string
|
||||
stringToUTF8(const std::string& str);
|
||||
|
||||
std::string
|
||||
bufferToString(const std::vector<unsigned char>& data);
|
||||
|
||||
template<typename T>
|
||||
static inline bool readAs(const std::string& str, T& data)
|
||||
boost::optional<T> readAs(const std::string& str)
|
||||
{
|
||||
T res;
|
||||
|
||||
std::istringstream iss ( str );
|
||||
iss >> data;
|
||||
return !iss.fail();
|
||||
iss >> res;
|
||||
if (iss.fail())
|
||||
return boost::none;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<>
|
||||
boost::optional<Wt::WDate> readAs(const std::string& str);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user