format support both raw and STL strings

This commit is contained in:
tokiloki 2013-08-15 17:10:12 +03:00
parent fd6433eb4e
commit a499447b6a
2 changed files with 16 additions and 2 deletions

View File

@ -226,8 +226,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

@ -325,7 +325,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");