From 5b336ac46f60606cdcf77889d624ce15cdd62530 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 19 Oct 2015 15:28:19 +0200 Subject: Implement package search by terms --- brep/package-traits.cxx | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 brep/package-traits.cxx (limited to 'brep/package-traits.cxx') diff --git a/brep/package-traits.cxx b/brep/package-traits.cxx new file mode 100644 index 0000000..cd30d81 --- /dev/null +++ b/brep/package-traits.cxx @@ -0,0 +1,70 @@ +// file : brep/package-traits.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include +#include +#include // memcpy + +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + static inline void + to_pg_string (ostream& os, const string& s) + { + os << '"'; + + for (auto c: s) + { + if (c == '\\' || c == '"') + os << '\\'; + + os << c; + } + + os << '"'; + } + + // Convert C++ weighted_text struct to PostgreSQL weighted_text + // composite type. + // + void value_traits:: + set_image (details::buffer& b, + size_t& n, + bool& is_null, + const value_type& v) + { + is_null = v.a.empty () && v.b.empty () && v.c.empty () && v.d.empty (); + + if (!is_null) + { + ostringstream o; + o << "("; + to_pg_string (o, v.a); + o << ","; + to_pg_string (o, v.b); + o << ","; + to_pg_string (o, v.c); + o << ","; + to_pg_string (o, v.d); + o << ")"; + + const string& s (o.str ()); + n = s.size (); + + if (n > b.capacity ()) + b.capacity (n); + + memcpy (b.data (), s.c_str (), n); + } + } + } +} -- cgit v1.1