Skip to content

Commit b81438e

Browse files
authored
Merge pull request Tencent#1307 from moretromain/preprocessor_cleanup
Rename a few internal preprocessor macros to avoid naming conflicts
2 parents 7e68aa0 + 4595cc4 commit b81438e

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

include/rapidjson/encodings.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ struct UTF8 {
144144

145145
template <typename InputStream>
146146
static bool Decode(InputStream& is, unsigned* codepoint) {
147-
#define COPY() c = is.Take(); *codepoint = (*codepoint << 6) | (static_cast<unsigned char>(c) & 0x3Fu)
148-
#define TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
149-
#define TAIL() COPY(); TRANS(0x70)
147+
#define RAPIDJSON_COPY() c = is.Take(); *codepoint = (*codepoint << 6) | (static_cast<unsigned char>(c) & 0x3Fu)
148+
#define RAPIDJSON_TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
149+
#define RAPIDJSON_TAIL() RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x70)
150150
typename InputStream::Ch c = is.Take();
151151
if (!(c & 0x80)) {
152152
*codepoint = static_cast<unsigned char>(c);
@@ -161,44 +161,44 @@ struct UTF8 {
161161
}
162162
bool result = true;
163163
switch (type) {
164-
case 2: TAIL(); return result;
165-
case 3: TAIL(); TAIL(); return result;
166-
case 4: COPY(); TRANS(0x50); TAIL(); return result;
167-
case 5: COPY(); TRANS(0x10); TAIL(); TAIL(); return result;
168-
case 6: TAIL(); TAIL(); TAIL(); return result;
169-
case 10: COPY(); TRANS(0x20); TAIL(); return result;
170-
case 11: COPY(); TRANS(0x60); TAIL(); TAIL(); return result;
164+
case 2: RAPIDJSON_TAIL(); return result;
165+
case 3: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
166+
case 4: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x50); RAPIDJSON_TAIL(); return result;
167+
case 5: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x10); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
168+
case 6: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
169+
case 10: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x20); RAPIDJSON_TAIL(); return result;
170+
case 11: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x60); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
171171
default: return false;
172172
}
173-
#undef COPY
174-
#undef TRANS
175-
#undef TAIL
173+
#undef RAPIDJSON_COPY
174+
#undef RAPIDJSON_TRANS
175+
#undef RAPIDJSON_TAIL
176176
}
177177

178178
template <typename InputStream, typename OutputStream>
179179
static bool Validate(InputStream& is, OutputStream& os) {
180-
#define COPY() os.Put(c = is.Take())
181-
#define TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
182-
#define TAIL() COPY(); TRANS(0x70)
180+
#define RAPIDJSON_COPY() os.Put(c = is.Take())
181+
#define RAPIDJSON_TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
182+
#define RAPIDJSON_TAIL() RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x70)
183183
Ch c;
184-
COPY();
184+
RAPIDJSON_COPY();
185185
if (!(c & 0x80))
186186
return true;
187187

188188
bool result = true;
189189
switch (GetRange(static_cast<unsigned char>(c))) {
190-
case 2: TAIL(); return result;
191-
case 3: TAIL(); TAIL(); return result;
192-
case 4: COPY(); TRANS(0x50); TAIL(); return result;
193-
case 5: COPY(); TRANS(0x10); TAIL(); TAIL(); return result;
194-
case 6: TAIL(); TAIL(); TAIL(); return result;
195-
case 10: COPY(); TRANS(0x20); TAIL(); return result;
196-
case 11: COPY(); TRANS(0x60); TAIL(); TAIL(); return result;
190+
case 2: RAPIDJSON_TAIL(); return result;
191+
case 3: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
192+
case 4: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x50); RAPIDJSON_TAIL(); return result;
193+
case 5: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x10); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
194+
case 6: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
195+
case 10: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x20); RAPIDJSON_TAIL(); return result;
196+
case 11: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x60); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
197197
default: return false;
198198
}
199-
#undef COPY
200-
#undef TRANS
201-
#undef TAIL
199+
#undef RAPIDJSON_COPY
200+
#undef RAPIDJSON_TRANS
201+
#undef RAPIDJSON_TAIL
202202
}
203203

204204
static unsigned char GetRange(unsigned char c) {

0 commit comments

Comments
 (0)