separated unsigned long long support
put the better error message on a separate branch
This commit is contained in:
parent
62466cc3d9
commit
5dd604b481
41
format.cc
41
format.cc
@ -160,6 +160,12 @@ void fmt::BasicWriter<Char>::FormatDecimal(
|
|||||||
buffer[0] = internal::DIGITS[index];
|
buffer[0] = internal::DIGITS[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Char>
|
||||||
|
void fmt::BasicWriter<Char>::FormatDecimal(
|
||||||
|
CharPtr buffer, unsigned long long value, unsigned num_digits) {
|
||||||
|
return fmt::BasicWriter<Char>::FormatDecimal(buffer, static_cast<uint64_t>(value), num_digits);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
typename fmt::BasicWriter<Char>::CharPtr
|
typename fmt::BasicWriter<Char>::CharPtr
|
||||||
fmt::BasicWriter<Char>::PrepareFilledBuffer(
|
fmt::BasicWriter<Char>::PrepareFilledBuffer(
|
||||||
@ -409,14 +415,12 @@ void fmt::BasicFormatter<Char>::CheckSign(const Char *&s, const Arg &arg) {
|
|||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void fmt::BasicFormatter<Char>::DoFormat() {
|
void fmt::BasicFormatter<Char>::DoFormat() {
|
||||||
const Char *start = format_; // capture the format string before it is reset
|
const Char *start = format_;
|
||||||
const Char *original = format_;
|
|
||||||
format_ = 0;
|
format_ = 0;
|
||||||
next_arg_index_ = 0;
|
next_arg_index_ = 0;
|
||||||
const Char *s = start;
|
const Char *s = start;
|
||||||
typedef internal::Array<Char, BasicWriter<Char>::INLINE_BUFFER_SIZE> Buffer;
|
typedef internal::Array<Char, BasicWriter<Char>::INLINE_BUFFER_SIZE> Buffer;
|
||||||
BasicWriter<Char> &writer = *writer_;
|
BasicWriter<Char> &writer = *writer_;
|
||||||
try {
|
|
||||||
while (*s) {
|
while (*s) {
|
||||||
Char c = *s++;
|
Char c = *s++;
|
||||||
if (c != '{' && c != '}') continue;
|
if (c != '{' && c != '}') continue;
|
||||||
@ -548,7 +552,7 @@ void fmt::BasicFormatter<Char>::DoFormat() {
|
|||||||
}
|
}
|
||||||
if (value > INT_MAX)
|
if (value > INT_MAX)
|
||||||
ReportError(s, "number is too big in format");
|
ReportError(s, "number is too big in format");
|
||||||
precision = static_cast<int>(value);
|
precision = value;
|
||||||
if (*s++ != '}')
|
if (*s++ != '}')
|
||||||
throw FormatError("unmatched '{' in format");
|
throw FormatError("unmatched '{' in format");
|
||||||
--num_open_braces_;
|
--num_open_braces_;
|
||||||
@ -646,11 +650,6 @@ void fmt::BasicFormatter<Char>::DoFormat() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const FormatError &e) {
|
|
||||||
// rethrow FormatError with the format string pointed to by start
|
|
||||||
throw BasicFormatError<Char>(e.what(), original);
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.buffer_.append(start, s);
|
writer.buffer_.append(start, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,6 +668,9 @@ template fmt::BasicWriter<char>::CharPtr
|
|||||||
template void fmt::BasicWriter<char>::FormatDecimal(
|
template void fmt::BasicWriter<char>::FormatDecimal(
|
||||||
CharPtr buffer, uint64_t value, unsigned num_digits);
|
CharPtr buffer, uint64_t value, unsigned num_digits);
|
||||||
|
|
||||||
|
template void fmt::BasicWriter<char>::FormatDecimal(
|
||||||
|
CharPtr buffer, unsigned long long value, unsigned num_digits);
|
||||||
|
|
||||||
template fmt::BasicWriter<char>::CharPtr
|
template fmt::BasicWriter<char>::CharPtr
|
||||||
fmt::BasicWriter<char>::PrepareFilledBuffer(
|
fmt::BasicWriter<char>::PrepareFilledBuffer(
|
||||||
unsigned size, const AlignSpec &spec, char sign);
|
unsigned size, const AlignSpec &spec, char sign);
|
||||||
@ -686,17 +688,6 @@ template void fmt::BasicFormatter<char>::CheckSign(
|
|||||||
|
|
||||||
template void fmt::BasicFormatter<char>::DoFormat();
|
template void fmt::BasicFormatter<char>::DoFormat();
|
||||||
|
|
||||||
const char* FormatErrorMessage(const std::string &message, const char* format) {
|
|
||||||
return fmt::c_str(fmt::Format("error: {} while parsing {}") << message << format);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> fmt::BasicFormatError<char>::BasicFormatError(const std::string &message, const char *format)
|
|
||||||
: std::runtime_error(FormatErrorMessage(message, format)), format_(format) {}
|
|
||||||
|
|
||||||
template<> fmt::BasicFormatError<char>::~BasicFormatError() {
|
|
||||||
std::runtime_error::~runtime_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit instantiations for wchar_t.
|
// Explicit instantiations for wchar_t.
|
||||||
|
|
||||||
template void fmt::BasicWriter<wchar_t>::FormatDouble<double>(
|
template void fmt::BasicWriter<wchar_t>::FormatDouble<double>(
|
||||||
@ -712,6 +703,9 @@ template fmt::BasicWriter<wchar_t>::CharPtr
|
|||||||
template void fmt::BasicWriter<wchar_t>::FormatDecimal(
|
template void fmt::BasicWriter<wchar_t>::FormatDecimal(
|
||||||
CharPtr buffer, uint64_t value, unsigned num_digits);
|
CharPtr buffer, uint64_t value, unsigned num_digits);
|
||||||
|
|
||||||
|
template void fmt::BasicWriter<wchar_t>::FormatDecimal(
|
||||||
|
CharPtr buffer, unsigned long long value, unsigned num_digits);
|
||||||
|
|
||||||
template fmt::BasicWriter<wchar_t>::CharPtr
|
template fmt::BasicWriter<wchar_t>::CharPtr
|
||||||
fmt::BasicWriter<wchar_t>::PrepareFilledBuffer(
|
fmt::BasicWriter<wchar_t>::PrepareFilledBuffer(
|
||||||
unsigned size, const AlignSpec &spec, char sign);
|
unsigned size, const AlignSpec &spec, char sign);
|
||||||
@ -729,10 +723,3 @@ template void fmt::BasicFormatter<wchar_t>::CheckSign(
|
|||||||
const wchar_t *&s, const Arg &arg);
|
const wchar_t *&s, const Arg &arg);
|
||||||
|
|
||||||
template void fmt::BasicFormatter<wchar_t>::DoFormat();
|
template void fmt::BasicFormatter<wchar_t>::DoFormat();
|
||||||
|
|
||||||
template<> fmt::BasicFormatError<wchar_t>::BasicFormatError(const std::string &message, const wchar_t *format)
|
|
||||||
: std::runtime_error(message), format_(format){}
|
|
||||||
|
|
||||||
template<> fmt::BasicFormatError<wchar_t>::~BasicFormatError() {
|
|
||||||
std::runtime_error::~runtime_error();
|
|
||||||
}
|
|
||||||
|
|||||||
14
format.h
14
format.h
@ -292,16 +292,6 @@ class FormatError : public std::runtime_error {
|
|||||||
: std::runtime_error(message) {}
|
: std::runtime_error(message) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char>
|
|
||||||
class BasicFormatError : public std::runtime_error {
|
|
||||||
private:
|
|
||||||
std::basic_string<Char> format_;
|
|
||||||
public:
|
|
||||||
explicit BasicFormatError(const std::string &message, const Char *format);
|
|
||||||
virtual ~BasicFormatError() throw();
|
|
||||||
const Char *format() const { return format_.c_str(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Alignment {
|
enum Alignment {
|
||||||
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
|
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
|
||||||
};
|
};
|
||||||
@ -521,6 +511,9 @@ class BasicWriter {
|
|||||||
static void FormatDecimal(
|
static void FormatDecimal(
|
||||||
CharPtr buffer, uint64_t value, unsigned num_digits);
|
CharPtr buffer, uint64_t value, unsigned num_digits);
|
||||||
|
|
||||||
|
static void FormatDecimal(
|
||||||
|
CharPtr buffer, unsigned long long value, unsigned num_digits);
|
||||||
|
|
||||||
static CharPtr FillPadding(CharPtr buffer,
|
static CharPtr FillPadding(CharPtr buffer,
|
||||||
unsigned total_size, std::size_t content_size, wchar_t fill);
|
unsigned total_size, std::size_t content_size, wchar_t fill);
|
||||||
|
|
||||||
@ -1203,6 +1196,7 @@ class FormatInt {
|
|||||||
}
|
}
|
||||||
explicit FormatInt(unsigned value) : str_(FormatDecimal(value)) {}
|
explicit FormatInt(unsigned value) : str_(FormatDecimal(value)) {}
|
||||||
explicit FormatInt(uint64_t value) : str_(FormatDecimal(value)) {}
|
explicit FormatInt(uint64_t value) : str_(FormatDecimal(value)) {}
|
||||||
|
explicit FormatInt(unsigned long long value) : str_(FormatDecimal(value)) {}
|
||||||
|
|
||||||
inline const char *c_str() const { return str_; }
|
inline const char *c_str() const { return str_; }
|
||||||
inline std::string str() const { return str_; }
|
inline std::string str() const { return str_; }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user