Skip to content

Commit dd46813

Browse files
committed
Change naming convention from _member to member_ (fixes #1905)
Ported from 31ce648
1 parent 5d79678 commit dd46813

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+789
-786
lines changed

extras/tests/Helpers/Allocators.hpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ class AllocatorLog {
6262
};
6363

6464
AllocatorLog& operator<<(const std::string& s) {
65-
_log << s << "\n";
65+
log_ << s << "\n";
6666
return *this;
6767
}
6868

6969
std::string str() const {
70-
auto s = _log.str();
70+
auto s = log_.str();
7171
if (s.empty())
7272
return "(empty)";
7373
s.pop_back(); // remove the trailing '\n'
@@ -84,57 +84,57 @@ class AllocatorLog {
8484
}
8585

8686
private:
87-
std::ostringstream _log;
87+
std::ostringstream log_;
8888
};
8989

9090
class SpyingAllocator : public ArduinoJson::Allocator {
9191
public:
9292
SpyingAllocator(
9393
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
94-
: _upstream(upstream) {}
94+
: upstream_(upstream) {}
9595
virtual ~SpyingAllocator() {}
9696

9797
void* allocate(size_t n) override {
9898
auto block = reinterpret_cast<AllocatedBlock*>(
99-
_upstream->allocate(sizeof(AllocatedBlock) + n - 1));
99+
upstream_->allocate(sizeof(AllocatedBlock) + n - 1));
100100
if (block) {
101-
_log << AllocatorLog::Allocate(n);
101+
log_ << AllocatorLog::Allocate(n);
102102
block->size = n;
103103
return block->payload;
104104
} else {
105-
_log << AllocatorLog::AllocateFail(n);
105+
log_ << AllocatorLog::AllocateFail(n);
106106
return nullptr;
107107
}
108108
}
109109

110110
void deallocate(void* p) override {
111111
auto block = AllocatedBlock::fromPayload(p);
112-
_log << AllocatorLog::Deallocate(block->size);
113-
_upstream->deallocate(block);
112+
log_ << AllocatorLog::Deallocate(block->size);
113+
upstream_->deallocate(block);
114114
}
115115

116116
void* reallocate(void* p, size_t n) override {
117117
auto block = AllocatedBlock::fromPayload(p);
118118
auto oldSize = block->size;
119119
block = reinterpret_cast<AllocatedBlock*>(
120-
_upstream->reallocate(block, sizeof(AllocatedBlock) + n - 1));
120+
upstream_->reallocate(block, sizeof(AllocatedBlock) + n - 1));
121121
if (block) {
122-
_log << AllocatorLog::Reallocate(oldSize, n);
122+
log_ << AllocatorLog::Reallocate(oldSize, n);
123123
ARDUINOJSON_ASSERT(block->size == oldSize);
124124
block->size = n;
125125
return block->payload;
126126
} else {
127-
_log << AllocatorLog::ReallocateFail(oldSize, n);
127+
log_ << AllocatorLog::ReallocateFail(oldSize, n);
128128
return nullptr;
129129
}
130130
}
131131

132132
void clearLog() {
133-
_log = AllocatorLog();
133+
log_ = AllocatorLog();
134134
}
135135

136136
const AllocatorLog& log() const {
137-
return _log;
137+
return log_;
138138
}
139139

140140
private:
@@ -151,69 +151,69 @@ class SpyingAllocator : public ArduinoJson::Allocator {
151151
}
152152
};
153153

154-
AllocatorLog _log;
155-
Allocator* _upstream;
154+
AllocatorLog log_;
155+
Allocator* upstream_;
156156
};
157157

158158
class ControllableAllocator : public ArduinoJson::Allocator {
159159
public:
160160
ControllableAllocator(
161161
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
162-
: _enabled(true), _upstream(upstream) {}
162+
: enabled_(true), upstream_(upstream) {}
163163
virtual ~ControllableAllocator() {}
164164

165165
void* allocate(size_t n) override {
166-
return _enabled ? _upstream->allocate(n) : 0;
166+
return enabled_ ? upstream_->allocate(n) : 0;
167167
}
168168

169169
void deallocate(void* p) override {
170-
_upstream->deallocate(p);
170+
upstream_->deallocate(p);
171171
}
172172

173173
void* reallocate(void* ptr, size_t n) override {
174-
return _enabled ? _upstream->reallocate(ptr, n) : 0;
174+
return enabled_ ? upstream_->reallocate(ptr, n) : 0;
175175
}
176176

177177
void disable() {
178-
_enabled = false;
178+
enabled_ = false;
179179
}
180180

181181
private:
182-
bool _enabled;
183-
Allocator* _upstream;
182+
bool enabled_;
183+
Allocator* upstream_;
184184
};
185185

186186
class TimebombAllocator : public ArduinoJson::Allocator {
187187
public:
188188
TimebombAllocator(
189189
size_t initialCountdown,
190190
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
191-
: _countdown(initialCountdown), _upstream(upstream) {}
191+
: countdown_(initialCountdown), upstream_(upstream) {}
192192
virtual ~TimebombAllocator() {}
193193

194194
void* allocate(size_t n) override {
195-
if (!_countdown)
195+
if (!countdown_)
196196
return nullptr;
197-
_countdown--;
198-
return _upstream->allocate(n);
197+
countdown_--;
198+
return upstream_->allocate(n);
199199
}
200200

201201
void deallocate(void* p) override {
202-
_upstream->deallocate(p);
202+
upstream_->deallocate(p);
203203
}
204204

205205
void* reallocate(void* ptr, size_t n) override {
206-
if (!_countdown)
206+
if (!countdown_)
207207
return nullptr;
208-
_countdown--;
209-
return _upstream->reallocate(ptr, n);
208+
countdown_--;
209+
return upstream_->reallocate(ptr, n);
210210
}
211211

212212
void setCountdown(size_t value) {
213-
_countdown = value;
213+
countdown_ = value;
214214
}
215215

216216
private:
217-
size_t _countdown = 0;
218-
Allocator* _upstream;
217+
size_t countdown_ = 0;
218+
Allocator* upstream_;
219219
};

extras/tests/Helpers/CustomReader.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
#include <sstream>
88

99
class CustomReader {
10-
std::stringstream _stream;
10+
std::stringstream stream_;
1111

1212
public:
13-
CustomReader(const char* input) : _stream(input) {}
13+
CustomReader(const char* input) : stream_(input) {}
1414
CustomReader(const CustomReader&) = delete;
1515

1616
int read() {
17-
return _stream.get();
17+
return stream_.get();
1818
}
1919

2020
size_t readBytes(char* buffer, size_t length) {
21-
_stream.read(buffer, static_cast<std::streamsize>(length));
22-
return static_cast<size_t>(_stream.gcount());
21+
stream_.read(buffer, static_cast<std::streamsize>(length));
22+
return static_cast<size_t>(stream_.gcount());
2323
}
2424
};

extras/tests/Helpers/api/String.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,57 @@
99
// Reproduces Arduino's String class
1010
class String {
1111
public:
12-
String() : _maxCapacity(1024) {}
13-
explicit String(const char* s) : _str(s), _maxCapacity(1024) {}
12+
String() : maxCapacity_(1024) {}
13+
explicit String(const char* s) : str_(s), maxCapacity_(1024) {}
1414

1515
void limitCapacityTo(size_t maxCapacity) {
16-
_maxCapacity = maxCapacity;
16+
maxCapacity_ = maxCapacity;
1717
}
1818

1919
unsigned char concat(const char* s) {
2020
return concat(s, strlen(s));
2121
}
2222

2323
size_t length() const {
24-
return _str.size();
24+
return str_.size();
2525
}
2626

2727
const char* c_str() const {
28-
return _str.c_str();
28+
return str_.c_str();
2929
}
3030

3131
bool operator==(const char* s) const {
32-
return _str == s;
32+
return str_ == s;
3333
}
3434

3535
String& operator=(const char* s) {
36-
_str.assign(s);
36+
str_.assign(s);
3737
return *this;
3838
}
3939

4040
char operator[](unsigned int index) const {
41-
if (index >= _str.size())
41+
if (index >= str_.size())
4242
return 0;
43-
return _str[index];
43+
return str_[index];
4444
}
4545

4646
friend std::ostream& operator<<(std::ostream& lhs, const ::String& rhs) {
47-
lhs << rhs._str;
47+
lhs << rhs.str_;
4848
return lhs;
4949
}
5050

5151
protected:
5252
// This function is protected in most Arduino cores
5353
unsigned char concat(const char* s, size_t n) {
54-
if (_str.size() + n > _maxCapacity)
54+
if (str_.size() + n > maxCapacity_)
5555
return 0;
56-
_str.append(s, n);
56+
str_.append(s, n);
5757
return 1;
5858
}
5959

6060
private:
61-
std::string _str;
62-
size_t _maxCapacity;
61+
std::string str_;
62+
size_t maxCapacity_;
6363
};
6464

6565
class StringSumHelper : public ::String {};

extras/tests/JsonSerializer/CustomWriter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ class CustomWriter {
1212
CustomWriter& operator=(const CustomWriter&) = delete;
1313

1414
size_t write(uint8_t c) {
15-
_str.append(1, static_cast<char>(c));
15+
str_.append(1, static_cast<char>(c));
1616
return 1;
1717
}
1818

1919
size_t write(const uint8_t* s, size_t n) {
20-
_str.append(reinterpret_cast<const char*>(s), n);
20+
str_.append(reinterpret_cast<const char*>(s), n);
2121
return n;
2222
}
2323

2424
const std::string& str() const {
25-
return _str;
25+
return str_;
2626
}
2727

2828
private:
29-
std::string _str;
29+
std::string str_;
3030
};
3131

3232
TEST_CASE("CustomWriter") {

extras/tests/JsonVariant/converters.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ TEST_CASE("Custom converter with overloading") {
7474

7575
class Complex {
7676
public:
77-
explicit Complex(double r, double i) : _real(r), _imag(i) {}
77+
explicit Complex(double r, double i) : real_(r), imag_(i) {}
7878

7979
double real() const {
80-
return _real;
80+
return real_;
8181
}
8282

8383
double imag() const {
84-
return _imag;
84+
return imag_;
8585
}
8686

8787
private:
88-
double _real, _imag;
88+
double real_, imag_;
8989
};
9090

9191
namespace ArduinoJson {

extras/tests/Misc/Readers.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,19 @@ TEST_CASE("IteratorReader") {
170170

171171
class StreamStub : public Stream {
172172
public:
173-
StreamStub(const char* s) : _stream(s) {}
173+
StreamStub(const char* s) : stream_(s) {}
174174

175175
int read() {
176-
return _stream.get();
176+
return stream_.get();
177177
}
178178

179179
size_t readBytes(char* buffer, size_t length) {
180-
_stream.read(buffer, static_cast<std::streamsize>(length));
181-
return static_cast<size_t>(_stream.gcount());
180+
stream_.read(buffer, static_cast<std::streamsize>(length));
181+
return static_cast<size_t>(stream_.gcount());
182182
}
183183

184184
private:
185-
std::istringstream _stream;
185+
std::istringstream stream_;
186186
};
187187

188188
TEST_CASE("Reader<Stream>") {

extras/tests/Misc/conflicts.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,8 @@
5252
#define BLOCKSIZE
5353
#define CAPACITY
5454

55+
// issue #1905
56+
#define _current
57+
5558
// catch.hpp mutes several warnings, this file also allows to detect them
5659
#include "ArduinoJson.h"

extras/tests/Misc/printable.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ struct PrintAllAtOnce {
3434

3535
template <typename PrintPolicy>
3636
struct PrintableString : public Printable {
37-
PrintableString(const char* s) : _str(s), _total(0) {}
37+
PrintableString(const char* s) : str_(s), total_(0) {}
3838

3939
virtual size_t printTo(Print& p) const {
40-
size_t result = PrintPolicy::printStringTo(_str, p);
41-
_total += result;
40+
size_t result = PrintPolicy::printStringTo(str_, p);
41+
total_ += result;
4242
return result;
4343
}
4444

4545
size_t totalBytesWritten() const {
46-
return _total;
46+
return total_;
4747
}
4848

4949
private:
50-
std::string _str;
51-
mutable size_t _total;
50+
std::string str_;
51+
mutable size_t total_;
5252
};
5353

5454
TEST_CASE("Printable") {

0 commit comments

Comments
 (0)