summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-19 21:00:12 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-19 21:00:12 +0000
commitb5d8693dfdad195cb80545c9763b3105a63c7d7b (patch)
tree423e55b6df4147f068f85060bdbdc2da43a34213
parentRemove flto cos I'm sick of it randomly breaking stuff (diff)
downloadgentoobrowse-api-b5d8693dfdad195cb80545c9763b3105a63c7d7b.tar.bz2
gentoobrowse-api-b5d8693dfdad195cb80545c9763b3105a63c7d7b.tar.xz
gentoobrowse-api-b5d8693dfdad195cb80545c9763b3105a63c7d7b.zip
Add support for unpacking PostgreSQL text arrays from their string form
-rw-r--r--gentoobrowse-api/domain/portage-models.ice1
-rw-r--r--gentoobrowse-api/service/Jamfile.jam3
-rw-r--r--gentoobrowse-api/service/converters.cpp22
-rw-r--r--gentoobrowse-api/service/unpackPqTextArray.h27
-rw-r--r--gentoobrowse-api/service/unpackPqTextArray.ll64
5 files changed, 117 insertions, 0 deletions
diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice
index 744cbf5..4f98ce3 100644
--- a/gentoobrowse-api/domain/portage-models.ice
+++ b/gentoobrowse-api/domain/portage-models.ice
@@ -5,6 +5,7 @@
module Gentoo {
sequence<byte> Image;
+ sequence<string> StringList;
class Category {
["slicer:db:pkey"]
diff --git a/gentoobrowse-api/service/Jamfile.jam b/gentoobrowse-api/service/Jamfile.jam
index b29063e..777c453 100644
--- a/gentoobrowse-api/service/Jamfile.jam
+++ b/gentoobrowse-api/service/Jamfile.jam
@@ -1,8 +1,10 @@
import generators ;
import type ;
+import lex ;
lib gentoobrowse-service :
[ glob *.cpp ]
+ [ glob *.ll ]
[ glob-tree *.sql ]
[ glob ../domain/*.ice ]
:
@@ -18,6 +20,7 @@ lib gentoobrowse-service :
<library>..//boost_thread
<library>..//boost_date_time
<library>../..//glibmm
+ <include>.
: :
<include>.
<implicit-dependency>../api//gentoobrowse-api
diff --git a/gentoobrowse-api/service/converters.cpp b/gentoobrowse-api/service/converters.cpp
new file mode 100644
index 0000000..b0ffacf
--- /dev/null
+++ b/gentoobrowse-api/service/converters.cpp
@@ -0,0 +1,22 @@
+#include <portage-models.h>
+#include "unpackPqTextArray.h"
+#include <string>
+
+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 &)
+ {
+ return std::string();
+ }
+}
+
diff --git a/gentoobrowse-api/service/unpackPqTextArray.h b/gentoobrowse-api/service/unpackPqTextArray.h
new file mode 100644
index 0000000..246be71
--- /dev/null
+++ b/gentoobrowse-api/service/unpackPqTextArray.h
@@ -0,0 +1,27 @@
+#ifndef JSONFLEXLEXER_H
+#define JSONFLEXLEXER_H
+
+#include <portage-models.h>
+#ifndef yyFlexLexer
+#define yyFlexLexer pqBaseFlexLexer
+#include <FlexLexer.h>
+#endif
+
+namespace Portage {
+ namespace Utils {
+ class UnpackPqTextArray : public yyFlexLexer {
+ public:
+ UnpackPqTextArray(std::istream &, ::Gentoo::StringList & sl);
+
+ int yylex() override;
+ void LexerError(const char * msg) override;
+
+ private:
+ ::Gentoo::StringList & list;
+ };
+ }
+}
+
+#endif
+
+
diff --git a/gentoobrowse-api/service/unpackPqTextArray.ll b/gentoobrowse-api/service/unpackPqTextArray.ll
new file mode 100644
index 0000000..6281063
--- /dev/null
+++ b/gentoobrowse-api/service/unpackPqTextArray.ll
@@ -0,0 +1,64 @@
+%option batch
+%option c++
+%option noyywrap
+%option 8bit
+%option stack
+%option yylineno
+%option yyclass="Portage::Utils::UnpackPqTextArray"
+%option prefix="pqBase"
+
+%{
+#include "unpackPqTextArray.h"
+#include <boost/algorithm/string/trim.hpp>
+#pragma GCC diagnostic ignored "-Wsign-compare"
+%}
+
+begin "{"
+end "}"
+comma ,
+unquoted [^,\"}]+
+quoted (\"[^\"]+\")
+
+%x FIRST
+%x AFTER
+%x NEXT
+
+%%
+
+{begin} {
+ yy_push_state(FIRST);
+}
+<FIRST,AFTER>{end} {
+ yy_pop_state();
+}
+<FIRST,NEXT>{unquoted} {
+ list.push_back(YYText());
+ BEGIN(AFTER);
+}
+<FIRST,NEXT>{quoted} {
+ list.push_back(YYText());
+ boost::algorithm::trim_if(list.back(), [](auto c){ return c == '"'; });
+ BEGIN(AFTER);
+}
+<AFTER>{comma} {
+ BEGIN(NEXT);
+}
+
+%%
+
+namespace Portage {
+ namespace Utils {
+ UnpackPqTextArray::UnpackPqTextArray(std::istream & f, ::Gentoo::StringList & sl) :
+ yyFlexLexer(&f, NULL),
+ list(sl)
+ {
+ }
+
+ void
+ UnpackPqTextArray::LexerError(const char * msg)
+ {
+ throw std::runtime_error(msg);
+ }
+ }
+}
+