diff --git a/.gitignore b/.gitignore index e3412016..a4b0cd1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ */build/ +.idea/ +cmake-build-debug/ diff --git a/tutorial01/leptjson.c b/tutorial01/leptjson.c index 5299fe1d..e2f63dcd 100644 --- a/tutorial01/leptjson.c +++ b/tutorial01/leptjson.c @@ -5,17 +5,17 @@ #define EXPECT(c, ch) do { assert(*c->json == (ch)); c->json++; } while(0) typedef struct { - const char* json; -}lept_context; + const char *json; +} lept_context; -static void lept_parse_whitespace(lept_context* c) { +static void lept_parse_whitespace(lept_context *c) { const char *p = c->json; while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') p++; c->json = p; } -static int lept_parse_null(lept_context* c, lept_value* v) { +static int lept_parse_null(lept_context *c, lept_value *v) { EXPECT(c, 'n'); if (c->json[0] != 'u' || c->json[1] != 'l' || c->json[2] != 'l') return LEPT_PARSE_INVALID_VALUE; @@ -24,15 +24,18 @@ static int lept_parse_null(lept_context* c, lept_value* v) { return LEPT_PARSE_OK; } -static int lept_parse_value(lept_context* c, lept_value* v) { +static int lept_parse_value(lept_context *c, lept_value *v) { switch (*c->json) { - case 'n': return lept_parse_null(c, v); - case '\0': return LEPT_PARSE_EXPECT_VALUE; - default: return LEPT_PARSE_INVALID_VALUE; + case 'n': + return lept_parse_null(c, v); + case '\0': + return LEPT_PARSE_EXPECT_VALUE; + default: + return LEPT_PARSE_INVALID_VALUE; } } -int lept_parse(lept_value* v, const char* json) { +int lept_parse(lept_value *v, const char *json) { lept_context c; assert(v != NULL); c.json = json; @@ -41,7 +44,7 @@ int lept_parse(lept_value* v, const char* json) { return lept_parse_value(&c, v); } -lept_type lept_get_type(const lept_value* v) { +lept_type lept_get_type(const lept_value *v) { assert(v != NULL); return v->type; } diff --git a/tutorial01/leptjson.h b/tutorial01/leptjson.h index 9b65d22a..ae3f012a 100644 --- a/tutorial01/leptjson.h +++ b/tutorial01/leptjson.h @@ -1,11 +1,13 @@ #ifndef LEPTJSON_H__ #define LEPTJSON_H__ -typedef enum { LEPT_NULL, LEPT_FALSE, LEPT_TRUE, LEPT_NUMBER, LEPT_STRING, LEPT_ARRAY, LEPT_OBJECT } lept_type; +typedef enum { + LEPT_NULL, LEPT_FALSE, LEPT_TRUE, LEPT_NUMBER, LEPT_STRING, LEPT_ARRAY, LEPT_OBJECT +} lept_type; typedef struct { lept_type type; -}lept_value; +} lept_value; enum { LEPT_PARSE_OK = 0, @@ -14,8 +16,8 @@ enum { LEPT_PARSE_ROOT_NOT_SINGULAR }; -int lept_parse(lept_value* v, const char* json); +int lept_parse(lept_value *v, const char *json); -lept_type lept_get_type(const lept_value* v); +lept_type lept_get_type(const lept_value *v); #endif /* LEPTJSON_H__ */