Obey line length limit.

This commit is contained in:
Victor Zverovich 2014-07-26 09:45:03 -07:00
parent f634ccb344
commit 2a1c0c9969
2 changed files with 28 additions and 25 deletions

View File

@ -421,7 +421,8 @@ class fmt::internal::ArgFormatter :
const Char *format_; const Char *format_;
public: public:
ArgFormatter(fmt::BasicFormatter<Char> &f, fmt::FormatSpec &s, const Char *fmt) ArgFormatter(
fmt::BasicFormatter<Char> &f,fmt::FormatSpec &s, const Char *fmt)
: formatter_(f), writer_(f.writer()), spec_(s), format_(fmt) {} : formatter_(f), writer_(f.writer()), spec_(s), format_(fmt) {}
template <typename T> template <typename T>
@ -651,20 +652,20 @@ void fmt::BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
} }
template <typename Char> template <typename Char>
template <typename StringChar> template <typename StrChar>
void fmt::BasicWriter<Char>::write_str( void fmt::BasicWriter<Char>::write_str(
const Arg::StringValue<StringChar> &str, const FormatSpec &spec) { const Arg::StringValue<StrChar> &str, const FormatSpec &spec) {
// Check if StringChar is convertible to Char. // Check if StrChar is convertible to Char.
internal::CharTraits<Char>::convert(StringChar()); internal::CharTraits<Char>::convert(StrChar());
if (spec.type_ && spec.type_ != 's') if (spec.type_ && spec.type_ != 's')
internal::report_unknown_type(spec.type_, "string"); internal::report_unknown_type(spec.type_, "string");
const StringChar *s = str.value; const StrChar *s = str.value;
std::size_t size = str.size; std::size_t size = str.size;
if (size == 0) { if (size == 0) {
if (!s) if (!s)
throw FormatError("string pointer is null"); throw FormatError("string pointer is null");
if (*s) if (*s)
size = std::char_traits<StringChar>::length(s); size = std::char_traits<StrChar>::length(s);
} }
write_str(s, size, spec); write_str(s, size, spec);
} }
@ -699,12 +700,12 @@ void fmt::BasicFormatter<Char>::CheckSign(
const Char *&s, const Arg &arg) { const Char *&s, const Arg &arg) {
char sign = static_cast<char>(*s); char sign = static_cast<char>(*s);
if (arg.type > Arg::LAST_NUMERIC_TYPE) { if (arg.type > Arg::LAST_NUMERIC_TYPE) {
report_error_(s, report_error_(s, fmt::format(
fmt::format("format specifier '{}' requires numeric argument", sign).c_str()); "format specifier '{}' requires numeric argument", sign).c_str());
} }
if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) { if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) {
report_error_(s, report_error_(s, fmt::format(
fmt::format("format specifier '{}' requires signed argument", sign).c_str()); "format specifier '{}' requires signed argument", sign).c_str());
} }
++s; ++s;
} }

View File

@ -1337,13 +1337,13 @@ class BasicWriter {
void write_double(T value, const FormatSpec &spec); void write_double(T value, const FormatSpec &spec);
// Writes a formatted string. // Writes a formatted string.
template <typename StringChar> template <typename StrChar>
CharPtr write_str( CharPtr write_str(
const StringChar *s, std::size_t size, const AlignSpec &spec); const StrChar *s, std::size_t size, const AlignSpec &spec);
template <typename StringChar> template <typename StrChar>
void write_str( void write_str(
const internal::Arg::StringValue<StringChar> &str, const FormatSpec &spec); const internal::Arg::StringValue<StrChar> &str, const FormatSpec &spec);
// This method is private to disallow writing a wide string to a // This method is private to disallow writing a wide string to a
// char stream and vice versa. If you want to print a wide string // char stream and vice versa. If you want to print a wide string
@ -1502,9 +1502,9 @@ class BasicWriter {
return *this; return *this;
} }
template <typename StringChar> template <typename StrChar>
BasicWriter &operator<<(const StrFormatSpec<StringChar> &spec) { BasicWriter &operator<<(const StrFormatSpec<StrChar> &spec) {
const StringChar *s = spec.str(); const StrChar *s = spec.str();
// TODO: error if fill is not convertible to Char // TODO: error if fill is not convertible to Char
write_str(s, std::char_traits<Char>::length(s), spec); write_str(s, std::char_traits<Char>::length(s), spec);
return *this; return *this;
@ -1514,9 +1514,9 @@ class BasicWriter {
}; };
template <typename Char> template <typename Char>
template <typename StringChar> template <typename StrChar>
typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str( typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str(
const StringChar *s, std::size_t size, const AlignSpec &spec) { const StrChar *s, std::size_t size, const AlignSpec &spec) {
CharPtr out = CharPtr(); CharPtr out = CharPtr();
if (spec.width() > size) { if (spec.width() > size) {
out = GrowBuffer(spec.width()); out = GrowBuffer(spec.width());
@ -1560,7 +1560,8 @@ typename fmt::BasicWriter<Char>::CharPtr
CharPtr p = GrowBuffer(fill_size); CharPtr p = GrowBuffer(fill_size);
std::fill(p, p + fill_size, fill); std::fill(p, p + fill_size, fill);
} }
CharPtr result = PrepareBufferForInt(num_digits, subspec, prefix, prefix_size); CharPtr result = PrepareBufferForInt(
num_digits, subspec, prefix, prefix_size);
if (align == ALIGN_LEFT) { if (align == ALIGN_LEFT) {
CharPtr p = GrowBuffer(fill_size); CharPtr p = GrowBuffer(fill_size);
std::fill(p, p + fill_size, fill); std::fill(p, p + fill_size, fill);
@ -1651,7 +1652,8 @@ void BasicWriter<Char>::write_int(T value, const Spec &spec) {
do { do {
++num_digits; ++num_digits;
} while ((n >>= 1) != 0); } while ((n >>= 1) != 0);
Char *p = GetBase(PrepareBufferForInt(num_digits, spec, prefix, prefix_size)); Char *p = GetBase(PrepareBufferForInt(
num_digits, spec, prefix, prefix_size));
n = abs_value; n = abs_value;
do { do {
*p-- = '0' + (n & 1); *p-- = '0' + (n & 1);
@ -1917,9 +1919,9 @@ inline void FormatDec(char *&buffer, T value) {
#if FMT_GCC_VERSION #if FMT_GCC_VERSION
// Use the system_header pragma to suppress warnings about variadic macros // Use the system_header pragma to suppress warnings about variadic macros
// because suppressing -Wvariadic-macros with the diagnostic pragma doesn't work. // because suppressing -Wvariadic-macros with the diagnostic pragma doesn't
// It is used at the end because we want to suppress as little warnings as // work. It is used at the end because we want to suppress as little warnings
// possible. // as possible.
# pragma GCC system_header # pragma GCC system_header
#endif #endif