format: set ostream precision as if for strings

ostream conversions are converted to strings anyway, so we should treat
them as such earlier in the process.
This commit is contained in:
Danny Robson 2016-07-28 16:12:16 +10:00
parent fad8181842
commit c26c687912
2 changed files with 14 additions and 1 deletions

View File

@ -225,12 +225,12 @@ namespace util { namespace format { namespace detail {
return -1;
case specifier::kind::STRING:
case specifier::kind::OSTREAM:
return std::numeric_limits<int>::max ();
case specifier::kind::POINTER:
case specifier::kind::CHARACTER:
case specifier::kind::ESCAPE:
case specifier::kind::OSTREAM:
return 0;
}

View File

@ -2,6 +2,18 @@
#include "tap.hpp"
///////////////////////////////////////////////////////////////////////////////
struct userobj { };
static std::ostream&
operator<< (std::ostream &os, const userobj&)
{
return os << "userobj";
}
///////////////////////////////////////////////////////////////////////////////
int
main (void)
{
@ -121,6 +133,7 @@ main (void)
CHECK_RENDER ("%.64s", "foo", "foo");
CHECK_RENDER ("%3.1s", " f", "foo");
CHECK_RENDER ("%-3.1s", "f ", "foo");
CHECK_RENDER ("%!", "userobj", userobj {});
CHECK_RENDER ("%p", "0x1234567", (void*)0x01234567);
CHECK_RENDER ("%p", "0x1234567", (int*)0x01234567);