Merge pull request #266 from tokiloki/format

format support both raw and STL strings
This commit is contained in:
Aleksandar Fabijanic 2014-05-21 22:24:42 -05:00
commit 89b7228461
2 changed files with 16 additions and 2 deletions

View File

@ -206,8 +206,16 @@ namespace
}
break;
case 's':
str << RefAnyCast<std::string>(*itVal++);
{
const Any& val = *itVal++;
if (val.type() == typeid(char*))
str << AnyCast<char*>(val);
else if (val.type() == typeid(const char*))
str << AnyCast<const char*>(val);
else
str << RefAnyCast<std::string>(val);
break;
}
case 'z':
str << AnyCast<std::size_t>(*itVal++);
break;

View File

@ -305,7 +305,13 @@ void FormatTest::testString()
std::string foo("foo");
std::string s(format("%s", foo));
assert (s == "foo");
s = format("%s", "foo");
assert (s == "foo");
s = format("%s", static_cast<const char*>("foo"));
assert (s == "foo");
s = format("%5s", foo);
assert (s == " foo");