Merge 264d006dd2 into 04c2b05340
This commit is contained in:
commit
6efa9ba41c
23
format.cc
23
format.cc
@ -410,10 +410,12 @@ void fmt::BasicFormatter<Char>::CheckSign(const Char *&s, const Arg &arg) {
|
||||
template <typename Char>
|
||||
void fmt::BasicFormatter<Char>::DoFormat() {
|
||||
const Char *start = format_;
|
||||
const Char *original = format_; // capture the format string before it is reset
|
||||
format_ = 0;
|
||||
next_arg_index_ = 0;
|
||||
const Char *s = start;
|
||||
BasicWriter<Char> &writer = *writer_;
|
||||
try {
|
||||
while (*s) {
|
||||
Char c = *s++;
|
||||
if (c != '{' && c != '}') continue;
|
||||
@ -542,7 +544,7 @@ void fmt::BasicFormatter<Char>::DoFormat() {
|
||||
}
|
||||
if (value > INT_MAX)
|
||||
ReportError(s, "number is too big in format");
|
||||
precision = value;
|
||||
precision = static_cast<int>(value);
|
||||
if (*s++ != '}')
|
||||
throw FormatError("unmatched '{' in format");
|
||||
--num_open_braces_;
|
||||
@ -637,6 +639,11 @@ void fmt::BasicFormatter<Char>::DoFormat() {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -672,6 +679,13 @@ template void fmt::BasicFormatter<char>::CheckSign(
|
||||
|
||||
template void fmt::BasicFormatter<char>::DoFormat();
|
||||
|
||||
template<> fmt::BasicFormatError<char>::BasicFormatError(const std::string &message, const char *format)
|
||||
: std::runtime_error(message), format_(format) {}
|
||||
|
||||
template<> fmt::BasicFormatError<char>::~BasicFormatError() {
|
||||
std::runtime_error::~runtime_error();
|
||||
}
|
||||
|
||||
// Explicit instantiations for wchar_t.
|
||||
|
||||
template void fmt::BasicWriter<wchar_t>::FormatDouble<double>(
|
||||
@ -704,3 +718,10 @@ template void fmt::BasicFormatter<wchar_t>::CheckSign(
|
||||
const wchar_t *&s, const Arg &arg);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
13
format.h
13
format.h
@ -189,6 +189,9 @@ struct SignedIntTraits {
|
||||
template <>
|
||||
struct IntTraits<int> : SignedIntTraits<int, unsigned> {};
|
||||
|
||||
template <>
|
||||
struct IntTraits<uint32_t> : SignedIntTraits<uint32_t, unsigned> {};
|
||||
|
||||
template <>
|
||||
struct IntTraits<long> : SignedIntTraits<long, unsigned long> {};
|
||||
|
||||
@ -289,6 +292,16 @@ class FormatError : public std::runtime_error {
|
||||
: 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 {
|
||||
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user