From d6c98df792198c5c9687ed35a676efbc5e621e0f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 18 Aug 2015 09:33:44 -0700 Subject: clang-format all source --- src/core/json/json.h | 2 +- src/core/json/json_common.h | 2 +- src/core/json/json_reader.c | 36 ++++++++++++++++++-------------- src/core/json/json_reader.h | 2 +- src/core/json/json_string.c | 50 +++++++++++++++++---------------------------- src/core/json/json_writer.c | 33 ++++++++++++++++++------------ src/core/json/json_writer.h | 14 ++++++++----- 7 files changed, 72 insertions(+), 67 deletions(-) (limited to 'src/core/json') diff --git a/src/core/json/json.h b/src/core/json/json.h index cac18ad885..573584bf6f 100644 --- a/src/core/json/json.h +++ b/src/core/json/json.h @@ -85,4 +85,4 @@ char* grpc_json_dump_to_string(grpc_json* json, int indent); grpc_json* grpc_json_create(grpc_json_type type); void grpc_json_destroy(grpc_json* json); -#endif /* GRPC_INTERNAL_CORE_JSON_JSON_H */ +#endif /* GRPC_INTERNAL_CORE_JSON_JSON_H */ diff --git a/src/core/json/json_common.h b/src/core/json/json_common.h index 84bf375916..481695b38b 100644 --- a/src/core/json/json_common.h +++ b/src/core/json/json_common.h @@ -46,4 +46,4 @@ typedef enum { GRPC_JSON_TOP_LEVEL } grpc_json_type; -#endif /* GRPC_INTERNAL_CORE_JSON_JSON_COMMON_H */ +#endif /* GRPC_INTERNAL_CORE_JSON_JSON_COMMON_H */ diff --git a/src/core/json/json_reader.c b/src/core/json/json_reader.c index c14094c290..c22d4edd47 100644 --- a/src/core/json/json_reader.c +++ b/src/core/json/json_reader.c @@ -42,27 +42,26 @@ static void json_reader_string_clear(grpc_json_reader* reader) { } static void json_reader_string_add_char(grpc_json_reader* reader, - gpr_uint32 c) { + gpr_uint32 c) { reader->vtable->string_add_char(reader->userdata, c); } static void json_reader_string_add_utf32(grpc_json_reader* reader, - gpr_uint32 utf32) { + gpr_uint32 utf32) { reader->vtable->string_add_utf32(reader->userdata, utf32); } -static gpr_uint32 - grpc_json_reader_read_char(grpc_json_reader* reader) { +static gpr_uint32 grpc_json_reader_read_char(grpc_json_reader* reader) { return reader->vtable->read_char(reader->userdata); } static void json_reader_container_begins(grpc_json_reader* reader, - grpc_json_type type) { + grpc_json_type type) { reader->vtable->container_begins(reader->userdata, type); } -static grpc_json_type - grpc_json_reader_container_ends(grpc_json_reader* reader) { +static grpc_json_type grpc_json_reader_container_ends( + grpc_json_reader* reader) { return reader->vtable->container_ends(reader->userdata); } @@ -101,8 +100,9 @@ void grpc_json_reader_init(grpc_json_reader* reader, } int grpc_json_reader_is_complete(grpc_json_reader* reader) { - return ((reader->depth == 0) && ((reader->state == GRPC_JSON_STATE_END) || - (reader->state == GRPC_JSON_STATE_VALUE_END))); + return ((reader->depth == 0) && + ((reader->state == GRPC_JSON_STATE_END) || + (reader->state == GRPC_JSON_STATE_VALUE_END))); } grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { @@ -143,7 +143,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { case GRPC_JSON_STATE_OBJECT_KEY_STRING: case GRPC_JSON_STATE_VALUE_STRING: if (c != ' ') return GRPC_JSON_PARSE_ERROR; - if (reader->unicode_high_surrogate != 0) return GRPC_JSON_PARSE_ERROR; + if (reader->unicode_high_surrogate != 0) + return GRPC_JSON_PARSE_ERROR; json_reader_string_add_char(reader, c); break; @@ -169,7 +170,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { switch (reader->state) { case GRPC_JSON_STATE_OBJECT_KEY_STRING: case GRPC_JSON_STATE_VALUE_STRING: - if (reader->unicode_high_surrogate != 0) return GRPC_JSON_PARSE_ERROR; + if (reader->unicode_high_surrogate != 0) + return GRPC_JSON_PARSE_ERROR; json_reader_string_add_char(reader, c); break; @@ -253,7 +255,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { /* This is the \\ case. */ case GRPC_JSON_STATE_STRING_ESCAPE: - if (reader->unicode_high_surrogate != 0) return GRPC_JSON_PARSE_ERROR; + if (reader->unicode_high_surrogate != 0) + return GRPC_JSON_PARSE_ERROR; json_reader_string_add_char(reader, '\\'); if (reader->escaped_string_was_key) { reader->state = GRPC_JSON_STATE_OBJECT_KEY_STRING; @@ -276,7 +279,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { break; case GRPC_JSON_STATE_OBJECT_KEY_STRING: - if (reader->unicode_high_surrogate != 0) return GRPC_JSON_PARSE_ERROR; + if (reader->unicode_high_surrogate != 0) + return GRPC_JSON_PARSE_ERROR; if (c == '"') { reader->state = GRPC_JSON_STATE_OBJECT_KEY_END; json_reader_set_key(reader); @@ -288,7 +292,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { break; case GRPC_JSON_STATE_VALUE_STRING: - if (reader->unicode_high_surrogate != 0) return GRPC_JSON_PARSE_ERROR; + if (reader->unicode_high_surrogate != 0) + return GRPC_JSON_PARSE_ERROR; if (c == '"') { reader->state = GRPC_JSON_STATE_VALUE_END; json_reader_set_string(reader); @@ -438,7 +443,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { if (reader->unicode_high_surrogate == 0) return GRPC_JSON_PARSE_ERROR; utf32 = 0x10000; - utf32 += (gpr_uint32)((reader->unicode_high_surrogate - 0xd800) * 0x400); + utf32 += (gpr_uint32)( + (reader->unicode_high_surrogate - 0xd800) * 0x400); utf32 += (gpr_uint32)(reader->unicode_char - 0xdc00); json_reader_string_add_utf32(reader, utf32); reader->unicode_high_surrogate = 0; diff --git a/src/core/json/json_reader.h b/src/core/json/json_reader.h index b1a5ace8fb..4d5487f790 100644 --- a/src/core/json/json_reader.h +++ b/src/core/json/json_reader.h @@ -157,4 +157,4 @@ void grpc_json_reader_init(grpc_json_reader* reader, */ int grpc_json_reader_is_complete(grpc_json_reader* reader); -#endif /* GRPC_INTERNAL_CORE_JSON_JSON_READER_H */ +#endif /* GRPC_INTERNAL_CORE_JSON_JSON_READER_H */ diff --git a/src/core/json/json_string.c b/src/core/json/json_string.c index 03c1099167..e6622ec461 100644 --- a/src/core/json/json_string.c +++ b/src/core/json/json_string.c @@ -73,7 +73,6 @@ typedef struct { size_t allocated; } json_writer_userdata; - /* This function checks if there's enough space left in the output buffer, * and will enlarge it if necessary. We're only allocating chunks of 256 * bytes at a time (or multiples thereof). @@ -97,8 +96,8 @@ static void json_writer_output_char(void* userdata, char c) { state->free_space--; } -static void json_writer_output_string_with_len(void* userdata, - const char* str, size_t len) { +static void json_writer_output_string_with_len(void* userdata, const char* str, + size_t len) { json_writer_userdata* state = userdata; json_writer_output_check(userdata, len); memcpy(state->output + state->string_len, str, len); @@ -106,8 +105,7 @@ static void json_writer_output_string_with_len(void* userdata, state->free_space -= len; } -static void json_writer_output_string(void* userdata, - const char* str) { +static void json_writer_output_string(void* userdata, const char* str) { size_t len = strlen(str); json_writer_output_string_with_len(userdata, str, len); } @@ -184,8 +182,7 @@ static gpr_uint32 json_reader_read_char(void* userdata) { /* Helper function to create a new grpc_json object and link it into * our tree-in-progress inside our opaque structure. */ -static grpc_json* json_create_and_link(void* userdata, - grpc_json_type type) { +static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) { json_reader_userdata* state = userdata; grpc_json* json = grpc_json_create(type); @@ -201,7 +198,7 @@ static grpc_json* json_create_and_link(void* userdata, json->parent->child = json; } if (json->parent->type == GRPC_JSON_OBJECT) { - json->key = (char*) state->key; + json->key = (char*)state->key; } } if (!state->top) { @@ -261,13 +258,13 @@ static void json_reader_set_key(void* userdata) { static void json_reader_set_string(void* userdata) { json_reader_userdata* state = userdata; grpc_json* json = json_create_and_link(userdata, GRPC_JSON_STRING); - json->value = (char*) state->string; + json->value = (char*)state->string; } static int json_reader_set_number(void* userdata) { json_reader_userdata* state = userdata; grpc_json* json = json_create_and_link(userdata, GRPC_JSON_NUMBER); - json->value = (char*) state->string; + json->value = (char*)state->string; return 1; } @@ -287,32 +284,25 @@ static void json_reader_set_null(void* userdata) { } static grpc_json_reader_vtable reader_vtable = { - json_reader_string_clear, - json_reader_string_add_char, - json_reader_string_add_utf32, - json_reader_read_char, - json_reader_container_begins, - json_reader_container_ends, - json_reader_set_key, - json_reader_set_string, - json_reader_set_number, - json_reader_set_true, - json_reader_set_false, - json_reader_set_null -}; + json_reader_string_clear, json_reader_string_add_char, + json_reader_string_add_utf32, json_reader_read_char, + json_reader_container_begins, json_reader_container_ends, + json_reader_set_key, json_reader_set_string, + json_reader_set_number, json_reader_set_true, + json_reader_set_false, json_reader_set_null}; /* And finally, let's define our public API. */ grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) { grpc_json_reader reader; json_reader_userdata state; - grpc_json *json = NULL; + grpc_json* json = NULL; grpc_json_reader_status status; if (!input) return NULL; state.top = state.current_container = state.current_value = NULL; state.string = state.key = NULL; - state.string_ptr = state.input = (gpr_uint8*) input; + state.string_ptr = state.input = (gpr_uint8*)input; state.remaining_input = size; grpc_json_reader_init(&reader, &reader_vtable, &state); @@ -333,8 +323,8 @@ grpc_json* grpc_json_parse_string(char* input) { return grpc_json_parse_string_with_len(input, UNBOUND_JSON_STRING_LENGTH); } -static void json_dump_recursive(grpc_json_writer* writer, - grpc_json* json, int in_object) { +static void json_dump_recursive(grpc_json_writer* writer, grpc_json* json, + int in_object) { while (json) { if (in_object) grpc_json_writer_object_key(writer, json->key); @@ -370,10 +360,8 @@ static void json_dump_recursive(grpc_json_writer* writer, } static grpc_json_writer_vtable writer_vtable = { - json_writer_output_char, - json_writer_output_string, - json_writer_output_string_with_len -}; + json_writer_output_char, json_writer_output_string, + json_writer_output_string_with_len}; char* grpc_json_dump_to_string(grpc_json* json, int indent) { grpc_json_writer writer; diff --git a/src/core/json/json_writer.c b/src/core/json/json_writer.c index bed9a9bfa5..ca9c835825 100644 --- a/src/core/json/json_writer.c +++ b/src/core/json/json_writer.c @@ -41,11 +41,13 @@ static void json_writer_output_char(grpc_json_writer* writer, char c) { writer->vtable->output_char(writer->userdata, c); } -static void json_writer_output_string(grpc_json_writer* writer, const char* str) { +static void json_writer_output_string(grpc_json_writer* writer, + const char* str) { writer->vtable->output_string(writer->userdata, str); } -static void json_writer_output_string_with_len(grpc_json_writer* writer, const char* str, size_t len) { +static void json_writer_output_string_with_len(grpc_json_writer* writer, + const char* str, size_t len) { writer->vtable->output_string_with_len(writer->userdata, str, len); } @@ -58,8 +60,7 @@ void grpc_json_writer_init(grpc_json_writer* writer, int indent, writer->userdata = userdata; } -static void json_writer_output_indent( - grpc_json_writer* writer) { +static void json_writer_output_indent(grpc_json_writer* writer) { static const char spacesstr[] = " " " " @@ -99,14 +100,15 @@ static void json_writer_value_end(grpc_json_writer* writer) { } } -static void json_writer_escape_utf16(grpc_json_writer* writer, gpr_uint16 utf16) { +static void json_writer_escape_utf16(grpc_json_writer* writer, + gpr_uint16 utf16) { static const char hex[] = "0123456789abcdef"; json_writer_output_string_with_len(writer, "\\u", 2); json_writer_output_char(writer, hex[(utf16 >> 12) & 0x0f]); json_writer_output_char(writer, hex[(utf16 >> 8) & 0x0f]); json_writer_output_char(writer, hex[(utf16 >> 4) & 0x0f]); - json_writer_output_char(writer, hex[(utf16) & 0x0f]); + json_writer_output_char(writer, hex[(utf16)&0x0f]); } static void json_writer_escape_string(grpc_json_writer* writer, @@ -173,8 +175,8 @@ static void json_writer_escape_string(grpc_json_writer* writer, * Any other range is technically reserved for future usage, so if we * don't want the software to break in the future, we have to allow * anything else. The first non-unicode character is 0x110000. */ - if (((utf32 >= 0xd800) && (utf32 <= 0xdfff)) || - (utf32 >= 0x110000)) break; + if (((utf32 >= 0xd800) && (utf32 <= 0xdfff)) || (utf32 >= 0x110000)) + break; if (utf32 >= 0x10000) { /* If utf32 contains a character that is above 0xffff, it needs to be * broken down into a utf-16 surrogate pair. A surrogate pair is first @@ -194,7 +196,8 @@ static void json_writer_escape_string(grpc_json_writer* writer, */ utf32 -= 0x10000; json_writer_escape_utf16(writer, (gpr_uint16)(0xd800 | (utf32 >> 10))); - json_writer_escape_utf16(writer, (gpr_uint16)(0xdc00 | (utf32 & 0x3ff))); + json_writer_escape_utf16(writer, + (gpr_uint16)(0xdc00 | (utf32 & 0x3ff))); } else { json_writer_escape_utf16(writer, (gpr_uint16)utf32); } @@ -204,7 +207,8 @@ static void json_writer_escape_string(grpc_json_writer* writer, json_writer_output_char(writer, '"'); } -void grpc_json_writer_container_begins(grpc_json_writer* writer, grpc_json_type type) { +void grpc_json_writer_container_begins(grpc_json_writer* writer, + grpc_json_type type) { if (!writer->got_key) json_writer_value_end(writer); json_writer_output_indent(writer); json_writer_output_char(writer, type == GRPC_JSON_OBJECT ? '{' : '['); @@ -213,7 +217,8 @@ void grpc_json_writer_container_begins(grpc_json_writer* writer, grpc_json_type writer->depth++; } -void grpc_json_writer_container_ends(grpc_json_writer* writer, grpc_json_type type) { +void grpc_json_writer_container_ends(grpc_json_writer* writer, + grpc_json_type type) { if (writer->indent && !writer->container_empty) json_writer_output_char(writer, '\n'); writer->depth--; @@ -238,14 +243,16 @@ void grpc_json_writer_value_raw(grpc_json_writer* writer, const char* string) { writer->got_key = 0; } -void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, const char* string, size_t len) { +void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, + const char* string, size_t len) { if (!writer->got_key) json_writer_value_end(writer); json_writer_output_indent(writer); json_writer_output_string_with_len(writer, string, len); writer->got_key = 0; } -void grpc_json_writer_value_string(grpc_json_writer* writer, const char* string) { +void grpc_json_writer_value_string(grpc_json_writer* writer, + const char* string) { if (!writer->got_key) json_writer_value_end(writer); json_writer_output_indent(writer); json_writer_escape_string(writer, string); diff --git a/src/core/json/json_writer.h b/src/core/json/json_writer.h index dfa61a5fef..a299dfabf8 100644 --- a/src/core/json/json_writer.h +++ b/src/core/json/json_writer.h @@ -78,16 +78,20 @@ void grpc_json_writer_init(grpc_json_writer* writer, int indent, grpc_json_writer_vtable* vtable, void* userdata); /* Signals the beginning of a container. */ -void grpc_json_writer_container_begins(grpc_json_writer* writer, grpc_json_type type); +void grpc_json_writer_container_begins(grpc_json_writer* writer, + grpc_json_type type); /* Signals the end of a container. */ -void grpc_json_writer_container_ends(grpc_json_writer* writer, grpc_json_type type); +void grpc_json_writer_container_ends(grpc_json_writer* writer, + grpc_json_type type); /* Writes down an object key for the next value. */ void grpc_json_writer_object_key(grpc_json_writer* writer, const char* string); /* Sets a raw value. Useful for numbers. */ void grpc_json_writer_value_raw(grpc_json_writer* writer, const char* string); /* Sets a raw value with its length. Useful for values like true or false. */ -void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, const char* string, size_t len); +void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, + const char* string, size_t len); /* Sets a string value. It'll be escaped, and utf-8 validated. */ -void grpc_json_writer_value_string(grpc_json_writer* writer, const char* string); +void grpc_json_writer_value_string(grpc_json_writer* writer, + const char* string); -#endif /* GRPC_INTERNAL_CORE_JSON_JSON_WRITER_H */ +#endif /* GRPC_INTERNAL_CORE_JSON_JSON_WRITER_H */ -- cgit v1.2.3