diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-24 16:26:45 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-24 16:26:45 +0200 |
commit | 3831dbb9c8aa44654f218c4607f396558fce9747 (patch) | |
tree | 9b96e7bbc7e2a6bdc20b66c3798f6b6bbf68a7b1 | |
parent | 34cf74d6813c7113a1833371510cea6be22808cc (diff) |
Add support for string representation of sql_token
-rw-r--r-- | odb/sql-token.cxx | 28 | ||||
-rw-r--r-- | odb/sql-token.hxx | 6 |
2 files changed, 21 insertions, 13 deletions
diff --git a/odb/sql-token.cxx b/odb/sql-token.cxx index fe6b836..6fc548b 100644 --- a/odb/sql-token.cxx +++ b/odb/sql-token.cxx @@ -3,7 +3,7 @@ // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // license : GNU GPL v3; see accompanying LICENSE file -#include <iostream> +#include <ostream> #include <odb/sql-token.hxx> @@ -11,34 +11,36 @@ using namespace std; static char punctuation_literals[] = {';', ',', '(', ')', '='}; -ostream& -operator<< (ostream& os, sql_token const& t) +string sql_token:: +string () const { - switch (t.type ()) + switch (type ()) { case sql_token::t_eos: { - os << "<end-of-stream>"; - break; + return "<end-of-stream>"; } case sql_token::t_identifier: { - os << t.identifier (); - break; + return identifier (); } case sql_token::t_punctuation: { - os << punctuation_literals[t.punctuation ()]; - break; + return std::string (1, punctuation_literals[punctuation ()]); } case sql_token::t_string_lit: case sql_token::t_int_lit: case sql_token::t_float_lit: { - os << t.literal (); - break; + return literal (); } } - return os; + return ""; +} + +ostream& +operator<< (ostream& os, sql_token const& t) +{ + return os << t.string (); } diff --git a/odb/sql-token.hxx b/odb/sql-token.hxx index 4d9c7a1..2a00bae 100644 --- a/odb/sql-token.hxx +++ b/odb/sql-token.hxx @@ -59,6 +59,12 @@ public: std::string const& literal () const; + // Human-readable string representation. + // +public: + std::string + string () const; + // C-tors. // public: |