Skip to content

Commit 788ab1d

Browse files
committed
improve according to solution
1 parent 4c0b32c commit 788ab1d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tutorial02/leptjson.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "leptjson.h"
22
#include <assert.h> /* assert() */
33
#include <stdlib.h> /* NULL, strtod() */
4-
#include <string.h>
54
#include <math.h>
65
#define EXPECT(c, ch) do { assert(*c->json == (ch)); c->json++; } while(0)
76
#define ISDIGIT(ch) ((ch) >= '0' && (ch) <= '9')
@@ -20,12 +19,17 @@ static void lept_parse_whitespace(lept_context* c) {
2019

2120
static int lept_parse_literal(lept_context* c, lept_value* v,
2221
const char* json, int type) {
23-
int i, len = strlen(json);
24-
for(i = 0; i < len; ++i) {
22+
size_t i = 0;
23+
while(json[i]) {
2524
if(c->json[i] != json[i]) return LEPT_PARSE_INVALID_VALUE;
25+
++i;
2626
}
27+
/*
28+
for(i = 0; i < len; ++i) {
29+
if(c->json[i] != json[i]) return LEPT_PARSE_INVALID_VALUE;
30+
}*/
2731
v->type = type;
28-
c->json += len;
32+
c->json += i;
2933
return LEPT_PARSE_OK;
3034
}
3135

0 commit comments

Comments
 (0)