summaryrefslogtreecommitdiff
path: root/gentoobrowse-api/domain/converters.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gentoobrowse-api/domain/converters.cpp')
-rw-r--r--gentoobrowse-api/domain/converters.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/gentoobrowse-api/domain/converters.cpp b/gentoobrowse-api/domain/converters.cpp
new file mode 100644
index 0000000..9d0b795
--- /dev/null
+++ b/gentoobrowse-api/domain/converters.cpp
@@ -0,0 +1,42 @@
+#include <portage-models.h>
+#include "converters.h"
+#include "unpackPqTextArray.h"
+#include <string>
+#include <boost/algorithm/string/join.hpp>
+
+namespace Slicer {
+ ::Gentoo::StringList
+ unpackPqTextArray(const std::string & s)
+ {
+ ::Gentoo::StringList list;
+ std::stringstream ss(s);
+ ::Portage::Utils::UnpackPqTextArray l(ss, list);
+ l.yylex();
+ return list;
+ }
+
+ std::string
+ packPqTextArray(const ::Gentoo::StringList & l)
+ {
+ if (l.empty()) return "{}";
+ ::Gentoo::StringList l2(l);
+ for(auto & i : l2) {
+ boost::algorithm::replace_all(i, "\"", "\\\"");
+ i = "\"" + i + "\"";
+ }
+ return "{" + boost::algorithm::join(l2, ",") + "}";
+ }
+
+ boost::posix_time::ptime
+ shortDateToPosixTime(const std::string & s)
+ {
+ return boost::posix_time::ptime(boost::gregorian::from_simple_string(s));
+ }
+
+ std::string
+ posixTimeToShortDate(const boost::posix_time::ptime & s)
+ {
+ return boost::gregorian::to_sql_string(s.date());
+ }
+}
+