mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
FMT_NULLPTR -> FMT_NULL and improve formatting
This commit is contained in:
@ -171,7 +171,8 @@ int safe_strerror(
|
|||||||
: error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {}
|
: error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {}
|
||||||
|
|
||||||
int run() {
|
int run() {
|
||||||
strerror_r(0, FMT_NULLPTR, ""); // Suppress a warning about unused strerror_r.
|
// Suppress a warning about unused strerror_r.
|
||||||
|
strerror_r(0, FMT_NULL, "");
|
||||||
return handle(strerror_r(error_code_, buffer_, buffer_size_));
|
return handle(strerror_r(error_code_, buffer_, buffer_size_));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -312,7 +313,7 @@ FMT_FUNC internal::UTF8ToUTF16::UTF8ToUTF16(StringRef s) {
|
|||||||
FMT_THROW(WindowsError(ERROR_INVALID_PARAMETER, ERROR_MSG));
|
FMT_THROW(WindowsError(ERROR_INVALID_PARAMETER, ERROR_MSG));
|
||||||
int s_size = static_cast<int>(s.size());
|
int s_size = static_cast<int>(s.size());
|
||||||
int length = MultiByteToWideChar(
|
int length = MultiByteToWideChar(
|
||||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, FMT_NULLPTR, 0);
|
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, FMT_NULL, 0);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
||||||
buffer_.resize(length + 1);
|
buffer_.resize(length + 1);
|
||||||
@ -334,12 +335,13 @@ FMT_FUNC int internal::UTF16ToUTF8::convert(WStringRef s) {
|
|||||||
if (s.size() > INT_MAX)
|
if (s.size() > INT_MAX)
|
||||||
return ERROR_INVALID_PARAMETER;
|
return ERROR_INVALID_PARAMETER;
|
||||||
int s_size = static_cast<int>(s.size());
|
int s_size = static_cast<int>(s.size());
|
||||||
int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, FMT_NULLPTR, 0, FMT_NULLPTR, FMT_NULLPTR);
|
int length = WideCharToMultiByte(
|
||||||
|
CP_UTF8, 0, s.data(), s_size, FMT_NULL, 0, FMT_NULL, FMT_NULL);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return GetLastError();
|
return GetLastError();
|
||||||
buffer_.resize(length + 1);
|
buffer_.resize(length + 1);
|
||||||
length = WideCharToMultiByte(
|
length = WideCharToMultiByte(
|
||||||
CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, FMT_NULLPTR, FMT_NULLPTR);
|
CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, FMT_NULL, FMT_NULL);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return GetLastError();
|
return GetLastError();
|
||||||
buffer_[length] = 0;
|
buffer_[length] = 0;
|
||||||
@ -362,9 +364,10 @@ FMT_FUNC void internal::format_windows_error(
|
|||||||
buffer.resize(INLINE_BUFFER_SIZE);
|
buffer.resize(INLINE_BUFFER_SIZE);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
wchar_t *system_message = &buffer[0];
|
wchar_t *system_message = &buffer[0];
|
||||||
int result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
int result = FormatMessageW(
|
||||||
FMT_NULLPTR, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
system_message, static_cast<uint32_t>(buffer.size()), FMT_NULLPTR);
|
FMT_NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
system_message, static_cast<uint32_t>(buffer.size()), FMT_NULL);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
UTF16ToUTF8 utf8_message;
|
UTF16ToUTF8 utf8_message;
|
||||||
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
|
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
|
||||||
@ -408,7 +411,7 @@ void internal::ArgMap<Char>::init(const ArgList &args) {
|
|||||||
if (!map_.empty())
|
if (!map_.empty())
|
||||||
return;
|
return;
|
||||||
typedef internal::NamedArg<Char> NamedArg;
|
typedef internal::NamedArg<Char> NamedArg;
|
||||||
const NamedArg *named_arg = FMT_NULLPTR;
|
const NamedArg *named_arg = FMT_NULL;
|
||||||
bool use_values =
|
bool use_values =
|
||||||
args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
|
args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
|
||||||
if (use_values) {
|
if (use_values) {
|
||||||
|
22
fmt/format.h
22
fmt/format.h
@ -214,13 +214,13 @@ typedef __int64 intmax_t;
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FMT_NULLPTR
|
#ifndef FMT_NULL
|
||||||
# if FMT_HAS_FEATURE(cxx_nullptr) || \
|
# if FMT_HAS_FEATURE(cxx_nullptr) || \
|
||||||
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
|
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
|
||||||
FMT_MSC_VER >= 1600
|
FMT_MSC_VER >= 1600
|
||||||
# define FMT_NULLPTR nullptr
|
# define FMT_NULL nullptr
|
||||||
# else
|
# else
|
||||||
# define FMT_NULLPTR NULL
|
# define FMT_NULL NULL
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -643,7 +643,7 @@ class Buffer {
|
|||||||
std::size_t size_;
|
std::size_t size_;
|
||||||
std::size_t capacity_;
|
std::size_t capacity_;
|
||||||
|
|
||||||
Buffer(T *ptr = FMT_NULLPTR, std::size_t capacity = 0)
|
Buffer(T *ptr = FMT_NULL, std::size_t capacity = 0)
|
||||||
: ptr_(ptr), size_(0), capacity_(capacity) {}
|
: ptr_(ptr), size_(0), capacity_(capacity) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -773,7 +773,7 @@ void MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t size) {
|
|||||||
std::size_t new_capacity = this->capacity_ + this->capacity_ / 2;
|
std::size_t new_capacity = this->capacity_ + this->capacity_ / 2;
|
||||||
if (size > new_capacity)
|
if (size > new_capacity)
|
||||||
new_capacity = size;
|
new_capacity = size;
|
||||||
T *new_ptr = this->allocate(new_capacity, FMT_NULLPTR);
|
T *new_ptr = this->allocate(new_capacity, FMT_NULL);
|
||||||
// The following code doesn't throw, so the raw pointer above doesn't leak.
|
// The following code doesn't throw, so the raw pointer above doesn't leak.
|
||||||
std::uninitialized_copy(this->ptr_, this->ptr_ + this->size_,
|
std::uninitialized_copy(this->ptr_, this->ptr_ + this->size_,
|
||||||
make_ptr(new_ptr, new_capacity));
|
make_ptr(new_ptr, new_capacity));
|
||||||
@ -1897,14 +1897,14 @@ class ArgMap {
|
|||||||
public:
|
public:
|
||||||
FMT_API void init(const ArgList &args);
|
FMT_API void init(const ArgList &args);
|
||||||
|
|
||||||
const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const {
|
const internal::Arg *find(const fmt::BasicStringRef<Char> &name) const {
|
||||||
// The list is unsorted, so just return the first matching name.
|
// The list is unsorted, so just return the first matching name.
|
||||||
for (typename MapType::const_iterator it = map_.begin(), end = map_.end();
|
for (typename MapType::const_iterator it = map_.begin(), end = map_.end();
|
||||||
it != end; ++it) {
|
it != end; ++it) {
|
||||||
if (it->first == name)
|
if (it->first == name)
|
||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
return FMT_NULLPTR;
|
return FMT_NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1933,7 +1933,7 @@ class ArgFormatterBase : public ArgVisitor<Impl, void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void write(const char *value) {
|
void write(const char *value) {
|
||||||
Arg::StringValue<char> str = {value, value != FMT_NULLPTR ? std::strlen(value) : 0};
|
Arg::StringValue<char> str = {value, value ? std::strlen(value) : 0};
|
||||||
writer_.write_str(str, spec_);
|
writer_.write_str(str, spec_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3009,7 +3009,7 @@ void BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
|
|||||||
// Format using snprintf.
|
// Format using snprintf.
|
||||||
Char fill = internal::CharTraits<Char>::cast(spec.fill());
|
Char fill = internal::CharTraits<Char>::cast(spec.fill());
|
||||||
unsigned n = 0;
|
unsigned n = 0;
|
||||||
Char *start = FMT_NULLPTR;
|
Char *start = FMT_NULL;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
std::size_t buffer_size = buffer_.capacity() - offset;
|
std::size_t buffer_size = buffer_.capacity() - offset;
|
||||||
#if FMT_MSC_VER
|
#if FMT_MSC_VER
|
||||||
@ -3615,7 +3615,7 @@ inline internal::Arg BasicFormatter<Char, AF>::get_arg(
|
|||||||
|
|
||||||
template <typename Char, typename AF>
|
template <typename Char, typename AF>
|
||||||
inline internal::Arg BasicFormatter<Char, AF>::parse_arg_index(const Char *&s) {
|
inline internal::Arg BasicFormatter<Char, AF>::parse_arg_index(const Char *&s) {
|
||||||
const char *error = FMT_NULLPTR;
|
const char *error = FMT_NULL;
|
||||||
internal::Arg arg = *s < '0' || *s > '9' ?
|
internal::Arg arg = *s < '0' || *s > '9' ?
|
||||||
next_arg(error) : get_arg(internal::parse_nonnegative_int(s), error);
|
next_arg(error) : get_arg(internal::parse_nonnegative_int(s), error);
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -3633,7 +3633,7 @@ inline internal::Arg BasicFormatter<Char, AF>::parse_arg_name(const Char *&s) {
|
|||||||
do {
|
do {
|
||||||
c = *++s;
|
c = *++s;
|
||||||
} while (internal::is_name_start(c) || ('0' <= c && c <= '9'));
|
} while (internal::is_name_start(c) || ('0' <= c && c <= '9'));
|
||||||
const char *error = FMT_NULLPTR;
|
const char *error = FMT_NULL;
|
||||||
internal::Arg arg = get_arg(BasicStringRef<Char>(start, s - start), error);
|
internal::Arg arg = get_arg(BasicStringRef<Char>(start, s - start), error);
|
||||||
if (error)
|
if (error)
|
||||||
FMT_THROW(FormatError(error));
|
FMT_THROW(FormatError(error));
|
||||||
|
@ -79,7 +79,7 @@ void fmt::BufferedFile::close() {
|
|||||||
if (!file_)
|
if (!file_)
|
||||||
return;
|
return;
|
||||||
int result = FMT_SYSTEM(fclose(file_));
|
int result = FMT_SYSTEM(fclose(file_));
|
||||||
file_ = FMT_NULLPTR;
|
file_ = FMT_NULL;
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
FMT_THROW(SystemError(errno, "cannot close file"));
|
FMT_THROW(SystemError(errno, "cannot close file"));
|
||||||
}
|
}
|
||||||
|
16
fmt/posix.h
16
fmt/posix.h
@ -88,7 +88,7 @@ class BufferedFile {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructs a BufferedFile object which doesn't represent any file.
|
// Constructs a BufferedFile object which doesn't represent any file.
|
||||||
BufferedFile() FMT_NOEXCEPT : file_(FMT_NULLPTR) {}
|
BufferedFile() FMT_NOEXCEPT : file_(FMT_NULL) {}
|
||||||
|
|
||||||
// Destroys the object closing the file it represents if any.
|
// Destroys the object closing the file it represents if any.
|
||||||
~BufferedFile() FMT_NOEXCEPT;
|
~BufferedFile() FMT_NOEXCEPT;
|
||||||
@ -110,7 +110,7 @@ public:
|
|||||||
|
|
||||||
// A "move constructor" for moving from an lvalue.
|
// A "move constructor" for moving from an lvalue.
|
||||||
BufferedFile(BufferedFile &f) FMT_NOEXCEPT : file_(f.file_) {
|
BufferedFile(BufferedFile &f) FMT_NOEXCEPT : file_(f.file_) {
|
||||||
f.file_ = FMT_NULLPTR;
|
f.file_ = FMT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A "move assignment operator" for moving from a temporary.
|
// A "move assignment operator" for moving from a temporary.
|
||||||
@ -124,7 +124,7 @@ public:
|
|||||||
BufferedFile &operator=(BufferedFile &other) {
|
BufferedFile &operator=(BufferedFile &other) {
|
||||||
close();
|
close();
|
||||||
file_ = other.file_;
|
file_ = other.file_;
|
||||||
other.file_ = FMT_NULLPTR;
|
other.file_ = FMT_NULL;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ public:
|
|||||||
// BufferedFile file = BufferedFile(...);
|
// BufferedFile file = BufferedFile(...);
|
||||||
operator Proxy() FMT_NOEXCEPT {
|
operator Proxy() FMT_NOEXCEPT {
|
||||||
Proxy p = {file_};
|
Proxy p = {file_};
|
||||||
file_ = FMT_NULLPTR;
|
file_ = FMT_NULL;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,13 +142,13 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
BufferedFile(BufferedFile &&other) FMT_NOEXCEPT : file_(other.file_) {
|
BufferedFile(BufferedFile &&other) FMT_NOEXCEPT : file_(other.file_) {
|
||||||
other.file_ = FMT_NULLPTR;
|
other.file_ = FMT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedFile& operator=(BufferedFile &&other) {
|
BufferedFile& operator=(BufferedFile &&other) {
|
||||||
close();
|
close();
|
||||||
file_ = other.file_;
|
file_ = other.file_;
|
||||||
other.file_ = FMT_NULLPTR;
|
other.file_ = FMT_NULL;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -336,7 +336,7 @@ class Locale {
|
|||||||
public:
|
public:
|
||||||
typedef locale_t Type;
|
typedef locale_t Type;
|
||||||
|
|
||||||
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULLPTR)) {
|
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL)) {
|
||||||
if (!locale_)
|
if (!locale_)
|
||||||
FMT_THROW(fmt::SystemError(errno, "cannot create locale"));
|
FMT_THROW(fmt::SystemError(errno, "cannot create locale"));
|
||||||
}
|
}
|
||||||
@ -347,7 +347,7 @@ class Locale {
|
|||||||
// Converts string to floating-point number and advances str past the end
|
// Converts string to floating-point number and advances str past the end
|
||||||
// of the parsed input.
|
// of the parsed input.
|
||||||
double strtod(const char *&str) const {
|
double strtod(const char *&str) const {
|
||||||
char *end = FMT_NULLPTR;
|
char *end = FMT_NULL;
|
||||||
double result = strtod_l(str, &end, locale_);
|
double result = strtod_l(str, &end, locale_);
|
||||||
str = end;
|
str = end;
|
||||||
return result;
|
return result;
|
||||||
|
@ -341,7 +341,7 @@ template <typename Char, typename AF>
|
|||||||
internal::Arg PrintfFormatter<Char, AF>::get_arg(const Char *s,
|
internal::Arg PrintfFormatter<Char, AF>::get_arg(const Char *s,
|
||||||
unsigned arg_index) {
|
unsigned arg_index) {
|
||||||
(void)s;
|
(void)s;
|
||||||
const char *error = FMT_NULLPTR;
|
const char *error = FMT_NULL;
|
||||||
internal::Arg arg = arg_index == std::numeric_limits<unsigned>::max() ?
|
internal::Arg arg = arg_index == std::numeric_limits<unsigned>::max() ?
|
||||||
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -35,7 +35,7 @@ class StringBuffer : public Buffer<Char> {
|
|||||||
data_.resize(this->size_);
|
data_.resize(this->size_);
|
||||||
str.swap(data_);
|
str.swap(data_);
|
||||||
this->capacity_ = this->size_ = 0;
|
this->capacity_ = this->size_ = 0;
|
||||||
this->ptr_ = FMT_NULLPTR;
|
this->ptr_ = FMT_NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
18
fmt/time.h
18
fmt/time.h
@ -54,7 +54,7 @@ void format_arg(BasicFormatter<char, ArgFormatter> &f,
|
|||||||
}
|
}
|
||||||
format_str = end + 1;
|
format_str = end + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace internal{
|
namespace internal{
|
||||||
inline Null<> localtime_r(...) { return Null<>(); }
|
inline Null<> localtime_r(...) { return Null<>(); }
|
||||||
inline Null<> localtime_s(...) { return Null<>(); }
|
inline Null<> localtime_s(...) { return Null<>(); }
|
||||||
@ -75,7 +75,7 @@ inline std::tm localtime(std::time_t time) {
|
|||||||
return handle(localtime_r(&time_, &tm_));
|
return handle(localtime_r(&time_, &tm_));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle(std::tm* tm) { return tm != FMT_NULLPTR; }
|
bool handle(std::tm *tm) { return tm != FMT_NULL; }
|
||||||
|
|
||||||
bool handle(internal::Null<>) {
|
bool handle(internal::Null<>) {
|
||||||
using namespace fmt::internal;
|
using namespace fmt::internal;
|
||||||
@ -86,9 +86,9 @@ inline std::tm localtime(std::time_t time) {
|
|||||||
|
|
||||||
bool fallback(internal::Null<>) {
|
bool fallback(internal::Null<>) {
|
||||||
using namespace fmt::internal;
|
using namespace fmt::internal;
|
||||||
std::tm* tm = std::localtime(&time_);
|
std::tm *tm = std::localtime(&time_);
|
||||||
if (tm != FMT_NULLPTR) tm_ = *tm;
|
if (tm) tm_ = *tm;
|
||||||
return tm != FMT_NULLPTR;
|
return tm != FMT_NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
LocalTime lt(time);
|
LocalTime lt(time);
|
||||||
@ -112,7 +112,7 @@ inline std::tm gmtime(std::time_t time) {
|
|||||||
return handle(gmtime_r(&time_, &tm_));
|
return handle(gmtime_r(&time_, &tm_));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle(std::tm* tm) { return tm != FMT_NULLPTR; }
|
bool handle(std::tm *tm) { return tm != FMT_NULL; }
|
||||||
|
|
||||||
bool handle(internal::Null<>) {
|
bool handle(internal::Null<>) {
|
||||||
using namespace fmt::internal;
|
using namespace fmt::internal;
|
||||||
@ -122,9 +122,9 @@ inline std::tm gmtime(std::time_t time) {
|
|||||||
bool fallback(int res) { return res == 0; }
|
bool fallback(int res) { return res == 0; }
|
||||||
|
|
||||||
bool fallback(internal::Null<>) {
|
bool fallback(internal::Null<>) {
|
||||||
std::tm* tm = std::gmtime(&time_);
|
std::tm *tm = std::gmtime(&time_);
|
||||||
if (tm != FMT_NULLPTR) tm_ = *tm;
|
if (tm != FMT_NULL) tm_ = *tm;
|
||||||
return tm != FMT_NULLPTR;
|
return tm != FMT_NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
GMTime gt(time);
|
GMTime gt(time);
|
||||||
|
@ -36,8 +36,8 @@ class MockAllocator {
|
|||||||
MockAllocator() {}
|
MockAllocator() {}
|
||||||
MockAllocator(const MockAllocator &) {}
|
MockAllocator(const MockAllocator &) {}
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
MOCK_METHOD2_T(allocate, T* (std::size_t n, const T* h));
|
MOCK_METHOD2_T(allocate, T *(std::size_t n, const T *h));
|
||||||
MOCK_METHOD2_T(deallocate, void (T* p, std::size_t n));
|
MOCK_METHOD2_T(deallocate, void (T *p, std::size_t n));
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Allocator>
|
template <typename Allocator>
|
||||||
@ -78,8 +78,10 @@ class AllocatorRef {
|
|||||||
|
|
||||||
Allocator *get() const { return alloc_; }
|
Allocator *get() const { return alloc_; }
|
||||||
|
|
||||||
value_type* allocate(std::size_t n, const value_type* h) { return alloc_->allocate(n, h); }
|
value_type *allocate(std::size_t n, const value_type *h) {
|
||||||
void deallocate(value_type* p, std::size_t n) { alloc_->deallocate(p, n); }
|
return alloc_->allocate(n, h);
|
||||||
|
}
|
||||||
|
void deallocate(value_type *p, std::size_t n) { alloc_->deallocate(p, n); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FMT_MOCK_ALLOCATOR_H_
|
#endif // FMT_MOCK_ALLOCATOR_H_
|
||||||
|
Reference in New Issue
Block a user