Commit 342b76d2 authored by Victor Zverovich's avatar Victor Zverovich

Implement pad for wide strings.

parent 136ee89b
......@@ -504,9 +504,15 @@ DEFINE_INT_FORMATTERS(unsigned long long)
\endrst
*/
inline StrFormatSpec<char> pad(
const char *str, unsigned width, wchar_t fill = ' ') {
return StrFormatSpec<char>(str, AlignSpec(width, fill));
template <typename Char>
inline StrFormatSpec<Char> pad(
const Char *str, unsigned width, Char fill = ' ') {
return StrFormatSpec<Char>(str, AlignSpec(width, fill));
}
inline StrFormatSpec<wchar_t> pad(
const wchar_t *str, unsigned width, char fill = ' ') {
return StrFormatSpec<wchar_t>(str, AlignSpec(width, fill));
}
template <typename Char>
......@@ -712,10 +718,10 @@ class BasicWriter {
template <typename T, typename Spec>
BasicWriter &operator<<(const IntFormatSpec<T, Spec> &spec);
template <typename T>
BasicWriter &operator<<(const StrFormatSpec<T> &spec) {
const char *s = spec.str();
FormatString(s, std::strlen(s), spec);
template <typename StringChar>
BasicWriter &operator<<(const StrFormatSpec<StringChar> &spec) {
const StringChar *s = spec.str();
FormatString(s, std::char_traits<Char>::length(s), spec);
return *this;
}
......
......@@ -56,6 +56,7 @@ using fmt::Format;
using fmt::FormatError;
using fmt::StringRef;
using fmt::Writer;
using fmt::WWriter;
using fmt::pad;
#define FORMAT_TEST_THROW_(statement, expected_exception, message, fail) \
......@@ -447,6 +448,12 @@ TEST(WriterTest, PadString) {
EXPECT_EQ("test******", str(Writer() << pad("test", 10, '*')));
}
TEST(WriterTest, PadWString) {
EXPECT_EQ(L"test ", str(WWriter() << pad(L"test", 8)));
EXPECT_EQ(L"test******", str(WWriter() << pad(L"test", 10, '*')));
EXPECT_EQ(L"test******", str(WWriter() << pad(L"test", 10, L'*')));
}
TEST(WriterTest, NoConflictWithIOManip) {
using namespace std;
using namespace fmt;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment