mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-27 08:40:14 +00:00
Implement pad for wide strings.
This commit is contained in:
parent
136ee89bb4
commit
342b76d278
20
format.h
20
format.h
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user