Skip to content

Commit b85075f

Browse files
committed
refactor
1 parent f756843 commit b85075f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/support/json.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,25 @@ struct Value {
257257
while (*curr && is_json_space(*curr)) \
258258
curr++; \
259259
}
260+
#define skip_escaped_characters(ptr)\
261+
while (*ptr && *ptr != '"') {\
262+
if (*ptr == '\\' && *(ptr + 1)) {\
263+
ptr++;\
264+
}\
265+
ptr++;\
266+
}
267+
#define RUNTIME_ASSERT(condition)\
268+
if (!(condition)) {\
269+
std::cerr << "Assertion failed: " #condition << " at " << __FILE__ << ":" << __LINE__ << "\n";\
270+
std::terminate();\
271+
}
260272
skip();
261273
if (*curr == '"') {
262274
// String
263275
curr++;
264276
char* close = curr;
265-
while (*close && *close != '"') {
266-
if (*close == '\\' && *(close + 1)) {
267-
close++; // Skip escaped character
268-
}
269-
close++;
270-
}
271-
assert(*close == '"');
277+
skip_escaped_characters(close);
278+
RUNTIME_ASSERT(*close == '"');
272279
*close = 0; // end this string, and reuse it straight from the input
273280
setString(curr);
274281
curr = close + 1;
@@ -314,13 +321,8 @@ struct Value {
314321
if (*curr == '"') {
315322
curr++;
316323
char* close = curr;
317-
while (*close && *close != '"') {
318-
if (*close == '\\' && *(close + 1)) {
319-
close++; // Skip escaped character
320-
}
321-
close++;
322-
}
323-
assert(*close == '"');
324+
skip_escaped_characters(close);
325+
RUNTIME_ASSERT(*close == '"');
324326
*close = 0; // end this string, and reuse it straight from the input
325327
IString key(curr);
326328
curr = close + 1;

0 commit comments

Comments
 (0)