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) ...@@ -504,9 +504,15 @@ DEFINE_INT_FORMATTERS(unsigned long long)
\endrst \endrst
*/ */
inline StrFormatSpec<char> pad( template <typename Char>
const char *str, unsigned width, wchar_t fill = ' ') { inline StrFormatSpec<Char> pad(
return StrFormatSpec<char>(str, AlignSpec(width, fill)); 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> template <typename Char>
...@@ -712,10 +718,10 @@ class BasicWriter { ...@@ -712,10 +718,10 @@ class BasicWriter {
template <typename T, typename Spec> template <typename T, typename Spec>
BasicWriter &operator<<(const IntFormatSpec<T, Spec> &spec); BasicWriter &operator<<(const IntFormatSpec<T, Spec> &spec);
template <typename T> template <typename StringChar>
BasicWriter &operator<<(const StrFormatSpec<T> &spec) { BasicWriter &operator<<(const StrFormatSpec<StringChar> &spec) {
const char *s = spec.str(); const StringChar *s = spec.str();
FormatString(s, std::strlen(s), spec); FormatString(s, std::char_traits<Char>::length(s), spec);
return *this; return *this;
} }
......
...@@ -56,6 +56,7 @@ using fmt::Format; ...@@ -56,6 +56,7 @@ using fmt::Format;
using fmt::FormatError; using fmt::FormatError;
using fmt::StringRef; using fmt::StringRef;
using fmt::Writer; using fmt::Writer;
using fmt::WWriter;
using fmt::pad; using fmt::pad;
#define FORMAT_TEST_THROW_(statement, expected_exception, message, fail) \ #define FORMAT_TEST_THROW_(statement, expected_exception, message, fail) \
...@@ -447,6 +448,12 @@ TEST(WriterTest, PadString) { ...@@ -447,6 +448,12 @@ TEST(WriterTest, PadString) {
EXPECT_EQ("test******", str(Writer() << pad("test", 10, '*'))); 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) { TEST(WriterTest, NoConflictWithIOManip) {
using namespace std; using namespace std;
using namespace fmt; 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