supplement special format handling for Symbol datatype
This commit is contained in:
parent
7e7d5793e1
commit
6a3d4777be
3 changed files with 43 additions and 1 deletions
|
|
@ -123,8 +123,13 @@ namespace std { // forward declaration to avoid including <iostream>
|
|||
class basic_ostream;
|
||||
|
||||
typedef basic_ostream<char, char_traits<char> > ostream;
|
||||
|
||||
}
|
||||
|
||||
namespace lib {
|
||||
class Literal;
|
||||
class Symbol;
|
||||
}
|
||||
|
||||
|
||||
namespace util {
|
||||
|
|
@ -351,6 +356,21 @@ namespace util {
|
|||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _Fmt::Converter<lib::Literal>
|
||||
{
|
||||
static void
|
||||
dump (lib::Literal const& literal, Implementation& impl)
|
||||
{
|
||||
format (literal.empty()? "" : literal.c(), impl);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _Fmt::Converter<lib::Symbol>
|
||||
: _Fmt::Converter<lib::Literal>
|
||||
{ };
|
||||
|
||||
/** some custom types explicitly provide a string representation */
|
||||
template<typename VAL>
|
||||
struct _Fmt::Converter<VAL, typename enable_if< _shall_convert_toString<VAL> >::type>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
**
|
||||
** @todo for the (currently just planned as of 11/08) rules based configuration
|
||||
** in the Proc-Layer a explicit Symbol datatype will probably very helpful.
|
||||
** For now we just a typedef is sufficient. A real Symbol datatype should
|
||||
** For now just a typedef is sufficient. A real Symbol datatype should
|
||||
** - be definable by string constant
|
||||
** - integrate smoothly with std::string
|
||||
** - provide a unique numeric index for each distinct Symbol
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
#include "lib/format-string.hpp"
|
||||
#include "lib/symbol.hpp"
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
|
|
@ -180,6 +181,24 @@ namespace test {
|
|||
CHECK (_Fmt("%10s") % str == " Lumiera" );
|
||||
CHECK (_Fmt("%7.4s") %str == " Lumi" );
|
||||
CHECK (_Fmt("%10c") % str == " L" );
|
||||
|
||||
const char* pch("edit");
|
||||
CHECK (_Fmt("%s") % pch == "edit" );
|
||||
CHECK (_Fmt("%10s") % pch == " edit" );
|
||||
CHECK (_Fmt("%7.3s") %pch == " edi" );
|
||||
CHECK (_Fmt("%10c") % pch == " e" );
|
||||
|
||||
lib::Literal lit("your");
|
||||
CHECK (_Fmt("%s") % lit == "your" );
|
||||
CHECK (_Fmt("%10s") % lit == " your" );
|
||||
CHECK (_Fmt("%7.2s") %lit == " yo" );
|
||||
CHECK (_Fmt("%10c") % lit == " y" );
|
||||
|
||||
lib::Symbol sym("freedom");
|
||||
CHECK (_Fmt("%s") % sym == "freedom" );
|
||||
CHECK (_Fmt("%10s") % sym == " freedom" );
|
||||
CHECK (_Fmt("%7.5s") %sym == " freed" );
|
||||
CHECK (_Fmt("%10c") % sym == " f" );
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -248,6 +267,9 @@ namespace test {
|
|||
x.i_ = 42;
|
||||
CHECK (_Fmt("!!%s!!") % rv == "!!Number-042!!");
|
||||
CHECK (_Fmt("!!%s!!") % x == "!!Number-042!!");
|
||||
|
||||
lib::Symbol sym("42");
|
||||
CHECK (_Fmt("!!%s!!") % sym == "!!42!!"); // but especially Symbol datatype is explicitly treated like a string
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue