Skip to content

Commit 1daddec

Browse files
committed
FMT_NULLPTR -> FMT_NULL and improve formatting
1 parent d8867a2 commit 1daddec

File tree

8 files changed

+48
-43
lines changed

8 files changed

+48
-43
lines changed

fmt/format.cc

+11-8
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ int safe_strerror(
171171
: error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {}
172172

173173
int run() {
174-
strerror_r(0, FMT_NULLPTR, ""); // Suppress a warning about unused strerror_r.
174+
// Suppress a warning about unused strerror_r.
175+
strerror_r(0, FMT_NULL, "");
175176
return handle(strerror_r(error_code_, buffer_, buffer_size_));
176177
}
177178
};
@@ -312,7 +313,7 @@ FMT_FUNC internal::UTF8ToUTF16::UTF8ToUTF16(StringRef s) {
312313
FMT_THROW(WindowsError(ERROR_INVALID_PARAMETER, ERROR_MSG));
313314
int s_size = static_cast<int>(s.size());
314315
int length = MultiByteToWideChar(
315-
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, FMT_NULLPTR, 0);
316+
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, FMT_NULL, 0);
316317
if (length == 0)
317318
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
318319
buffer_.resize(length + 1);
@@ -334,12 +335,13 @@ FMT_FUNC int internal::UTF16ToUTF8::convert(WStringRef s) {
334335
if (s.size() > INT_MAX)
335336
return ERROR_INVALID_PARAMETER;
336337
int s_size = static_cast<int>(s.size());
337-
int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, FMT_NULLPTR, 0, FMT_NULLPTR, FMT_NULLPTR);
338+
int length = WideCharToMultiByte(
339+
CP_UTF8, 0, s.data(), s_size, FMT_NULL, 0, FMT_NULL, FMT_NULL);
338340
if (length == 0)
339341
return GetLastError();
340342
buffer_.resize(length + 1);
341343
length = WideCharToMultiByte(
342-
CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, FMT_NULLPTR, FMT_NULLPTR);
344+
CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, FMT_NULL, FMT_NULL);
343345
if (length == 0)
344346
return GetLastError();
345347
buffer_[length] = 0;
@@ -362,9 +364,10 @@ FMT_FUNC void internal::format_windows_error(
362364
buffer.resize(INLINE_BUFFER_SIZE);
363365
for (;;) {
364366
wchar_t *system_message = &buffer[0];
365-
int result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
366-
FMT_NULLPTR, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
367-
system_message, static_cast<uint32_t>(buffer.size()), FMT_NULLPTR);
367+
int result = FormatMessageW(
368+
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
369+
FMT_NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
370+
system_message, static_cast<uint32_t>(buffer.size()), FMT_NULL);
368371
if (result != 0) {
369372
UTF16ToUTF8 utf8_message;
370373
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
@@ -408,7 +411,7 @@ void internal::ArgMap<Char>::init(const ArgList &args) {
408411
if (!map_.empty())
409412
return;
410413
typedef internal::NamedArg<Char> NamedArg;
411-
const NamedArg *named_arg = FMT_NULLPTR;
414+
const NamedArg *named_arg = FMT_NULL;
412415
bool use_values =
413416
args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
414417
if (use_values) {

fmt/format.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ typedef __int64 intmax_t;
214214
# endif
215215
#endif
216216

217-
#ifndef FMT_NULLPTR
217+
#ifndef FMT_NULL
218218
# if FMT_HAS_FEATURE(cxx_nullptr) || \
219219
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
220220
FMT_MSC_VER >= 1600
221-
# define FMT_NULLPTR nullptr
221+
# define FMT_NULL nullptr
222222
# else
223-
# define FMT_NULLPTR NULL
223+
# define FMT_NULL NULL
224224
# endif
225225
#endif
226226

@@ -643,7 +643,7 @@ class Buffer {
643643
std::size_t size_;
644644
std::size_t capacity_;
645645

646-
Buffer(T *ptr = FMT_NULLPTR, std::size_t capacity = 0)
646+
Buffer(T *ptr = FMT_NULL, std::size_t capacity = 0)
647647
: ptr_(ptr), size_(0), capacity_(capacity) {}
648648

649649
/**
@@ -773,7 +773,7 @@ void MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t size) {
773773
std::size_t new_capacity = this->capacity_ + this->capacity_ / 2;
774774
if (size > new_capacity)
775775
new_capacity = size;
776-
T *new_ptr = this->allocate(new_capacity, FMT_NULLPTR);
776+
T *new_ptr = this->allocate(new_capacity, FMT_NULL);
777777
// The following code doesn't throw, so the raw pointer above doesn't leak.
778778
std::uninitialized_copy(this->ptr_, this->ptr_ + this->size_,
779779
make_ptr(new_ptr, new_capacity));
@@ -1897,14 +1897,14 @@ class ArgMap {
18971897
public:
18981898
FMT_API void init(const ArgList &args);
18991899

1900-
const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const {
1900+
const internal::Arg *find(const fmt::BasicStringRef<Char> &name) const {
19011901
// The list is unsorted, so just return the first matching name.
19021902
for (typename MapType::const_iterator it = map_.begin(), end = map_.end();
19031903
it != end; ++it) {
19041904
if (it->first == name)
19051905
return &it->second;
19061906
}
1907-
return FMT_NULLPTR;
1907+
return FMT_NULL;
19081908
}
19091909
};
19101910

@@ -1933,7 +1933,7 @@ class ArgFormatterBase : public ArgVisitor<Impl, void> {
19331933
}
19341934

19351935
void write(const char *value) {
1936-
Arg::StringValue<char> str = {value, value != FMT_NULLPTR ? std::strlen(value) : 0};
1936+
Arg::StringValue<char> str = {value, value ? std::strlen(value) : 0};
19371937
writer_.write_str(str, spec_);
19381938
}
19391939

@@ -3009,7 +3009,7 @@ void BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
30093009
// Format using snprintf.
30103010
Char fill = internal::CharTraits<Char>::cast(spec.fill());
30113011
unsigned n = 0;
3012-
Char *start = FMT_NULLPTR;
3012+
Char *start = FMT_NULL;
30133013
for (;;) {
30143014
std::size_t buffer_size = buffer_.capacity() - offset;
30153015
#if FMT_MSC_VER
@@ -3615,7 +3615,7 @@ inline internal::Arg BasicFormatter<Char, AF>::get_arg(
36153615

36163616
template <typename Char, typename AF>
36173617
inline internal::Arg BasicFormatter<Char, AF>::parse_arg_index(const Char *&s) {
3618-
const char *error = FMT_NULLPTR;
3618+
const char *error = FMT_NULL;
36193619
internal::Arg arg = *s < '0' || *s > '9' ?
36203620
next_arg(error) : get_arg(internal::parse_nonnegative_int(s), error);
36213621
if (error) {
@@ -3633,7 +3633,7 @@ inline internal::Arg BasicFormatter<Char, AF>::parse_arg_name(const Char *&s) {
36333633
do {
36343634
c = *++s;
36353635
} while (internal::is_name_start(c) || ('0' <= c && c <= '9'));
3636-
const char *error = FMT_NULLPTR;
3636+
const char *error = FMT_NULL;
36373637
internal::Arg arg = get_arg(BasicStringRef<Char>(start, s - start), error);
36383638
if (error)
36393639
FMT_THROW(FormatError(error));

fmt/posix.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void fmt::BufferedFile::close() {
7979
if (!file_)
8080
return;
8181
int result = FMT_SYSTEM(fclose(file_));
82-
file_ = FMT_NULLPTR;
82+
file_ = FMT_NULL;
8383
if (result != 0)
8484
FMT_THROW(SystemError(errno, "cannot close file"));
8585
}

fmt/posix.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class BufferedFile {
8888

8989
public:
9090
// Constructs a BufferedFile object which doesn't represent any file.
91-
BufferedFile() FMT_NOEXCEPT : file_(FMT_NULLPTR) {}
91+
BufferedFile() FMT_NOEXCEPT : file_(FMT_NULL) {}
9292

9393
// Destroys the object closing the file it represents if any.
9494
~BufferedFile() FMT_NOEXCEPT;
@@ -110,7 +110,7 @@ class BufferedFile {
110110

111111
// A "move constructor" for moving from an lvalue.
112112
BufferedFile(BufferedFile &f) FMT_NOEXCEPT : file_(f.file_) {
113-
f.file_ = FMT_NULLPTR;
113+
f.file_ = FMT_NULL;
114114
}
115115

116116
// A "move assignment operator" for moving from a temporary.
@@ -124,15 +124,15 @@ class BufferedFile {
124124
BufferedFile &operator=(BufferedFile &other) {
125125
close();
126126
file_ = other.file_;
127-
other.file_ = FMT_NULLPTR;
127+
other.file_ = FMT_NULL;
128128
return *this;
129129
}
130130

131131
// Returns a proxy object for moving from a temporary:
132132
// BufferedFile file = BufferedFile(...);
133133
operator Proxy() FMT_NOEXCEPT {
134134
Proxy p = {file_};
135-
file_ = FMT_NULLPTR;
135+
file_ = FMT_NULL;
136136
return p;
137137
}
138138

@@ -142,13 +142,13 @@ class BufferedFile {
142142

143143
public:
144144
BufferedFile(BufferedFile &&other) FMT_NOEXCEPT : file_(other.file_) {
145-
other.file_ = FMT_NULLPTR;
145+
other.file_ = FMT_NULL;
146146
}
147147

148148
BufferedFile& operator=(BufferedFile &&other) {
149149
close();
150150
file_ = other.file_;
151-
other.file_ = FMT_NULLPTR;
151+
other.file_ = FMT_NULL;
152152
return *this;
153153
}
154154
#endif
@@ -336,7 +336,7 @@ class Locale {
336336
public:
337337
typedef locale_t Type;
338338

339-
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULLPTR)) {
339+
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL)) {
340340
if (!locale_)
341341
FMT_THROW(fmt::SystemError(errno, "cannot create locale"));
342342
}
@@ -347,7 +347,7 @@ class Locale {
347347
// Converts string to floating-point number and advances str past the end
348348
// of the parsed input.
349349
double strtod(const char *&str) const {
350-
char *end = FMT_NULLPTR;
350+
char *end = FMT_NULL;
351351
double result = strtod_l(str, &end, locale_);
352352
str = end;
353353
return result;

fmt/printf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ template <typename Char, typename AF>
341341
internal::Arg PrintfFormatter<Char, AF>::get_arg(const Char *s,
342342
unsigned arg_index) {
343343
(void)s;
344-
const char *error = FMT_NULLPTR;
344+
const char *error = FMT_NULL;
345345
internal::Arg arg = arg_index == std::numeric_limits<unsigned>::max() ?
346346
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
347347
if (error)

fmt/string.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class StringBuffer : public Buffer<Char> {
3535
data_.resize(this->size_);
3636
str.swap(data_);
3737
this->capacity_ = this->size_ = 0;
38-
this->ptr_ = FMT_NULLPTR;
38+
this->ptr_ = FMT_NULL;
3939
}
4040
};
4141
} // namespace internal

fmt/time.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void format_arg(BasicFormatter<char, ArgFormatter> &f,
5454
}
5555
format_str = end + 1;
5656
}
57-
57+
5858
namespace internal{
5959
inline Null<> localtime_r(...) { return Null<>(); }
6060
inline Null<> localtime_s(...) { return Null<>(); }
@@ -75,7 +75,7 @@ inline std::tm localtime(std::time_t time) {
7575
return handle(localtime_r(&time_, &tm_));
7676
}
7777

78-
bool handle(std::tm* tm) { return tm != FMT_NULLPTR; }
78+
bool handle(std::tm *tm) { return tm != FMT_NULL; }
7979

8080
bool handle(internal::Null<>) {
8181
using namespace fmt::internal;
@@ -86,9 +86,9 @@ inline std::tm localtime(std::time_t time) {
8686

8787
bool fallback(internal::Null<>) {
8888
using namespace fmt::internal;
89-
std::tm* tm = std::localtime(&time_);
90-
if (tm != FMT_NULLPTR) tm_ = *tm;
91-
return tm != FMT_NULLPTR;
89+
std::tm *tm = std::localtime(&time_);
90+
if (tm) tm_ = *tm;
91+
return tm != FMT_NULL;
9292
}
9393
};
9494
LocalTime lt(time);
@@ -112,7 +112,7 @@ inline std::tm gmtime(std::time_t time) {
112112
return handle(gmtime_r(&time_, &tm_));
113113
}
114114

115-
bool handle(std::tm* tm) { return tm != FMT_NULLPTR; }
115+
bool handle(std::tm *tm) { return tm != FMT_NULL; }
116116

117117
bool handle(internal::Null<>) {
118118
using namespace fmt::internal;
@@ -122,9 +122,9 @@ inline std::tm gmtime(std::time_t time) {
122122
bool fallback(int res) { return res == 0; }
123123

124124
bool fallback(internal::Null<>) {
125-
std::tm* tm = std::gmtime(&time_);
126-
if (tm != FMT_NULLPTR) tm_ = *tm;
127-
return tm != FMT_NULLPTR;
125+
std::tm *tm = std::gmtime(&time_);
126+
if (tm != FMT_NULL) tm_ = *tm;
127+
return tm != FMT_NULL;
128128
}
129129
};
130130
GMTime gt(time);

test/mock-allocator.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class MockAllocator {
3636
MockAllocator() {}
3737
MockAllocator(const MockAllocator &) {}
3838
typedef T value_type;
39-
MOCK_METHOD2_T(allocate, T* (std::size_t n, const T* h));
40-
MOCK_METHOD2_T(deallocate, void (T* p, std::size_t n));
39+
MOCK_METHOD2_T(allocate, T *(std::size_t n, const T *h));
40+
MOCK_METHOD2_T(deallocate, void (T *p, std::size_t n));
4141
};
4242

4343
template <typename Allocator>
@@ -78,8 +78,10 @@ class AllocatorRef {
7878

7979
Allocator *get() const { return alloc_; }
8080

81-
value_type* allocate(std::size_t n, const value_type* h) { return alloc_->allocate(n, h); }
82-
void deallocate(value_type* p, std::size_t n) { alloc_->deallocate(p, n); }
81+
value_type *allocate(std::size_t n, const value_type *h) {
82+
return alloc_->allocate(n, h);
83+
}
84+
void deallocate(value_type *p, std::size_t n) { alloc_->deallocate(p, n); }
8385
};
8486

8587
#endif // FMT_MOCK_ALLOCATOR_H_

0 commit comments

Comments
 (0)