aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/json
diff options
context:
space:
mode:
authorGravatar Noah Eisen <ncteisen@google.com>2018-02-09 09:16:55 -0800
committerGravatar Noah Eisen <ncteisen@google.com>2018-02-09 09:16:55 -0800
commitbe82e64b3debcdb1d9ec6a149fc85af0d46bfb7e (patch)
treecc5e1234073eb250a2c319b5a4db2919fce060ea /src/core/lib/json
parent194436342137924b4fb7429bede037a4b5ec7edb (diff)
Autofix c casts to c++ casts
Diffstat (limited to 'src/core/lib/json')
-rw-r--r--src/core/lib/json/json.cc2
-rw-r--r--src/core/lib/json/json_reader.cc12
-rw-r--r--src/core/lib/json/json_string.cc36
-rw-r--r--src/core/lib/json/json_writer.cc16
4 files changed, 33 insertions, 33 deletions
diff --git a/src/core/lib/json/json.cc b/src/core/lib/json/json.cc
index 4ad51f662a..adf35b9088 100644
--- a/src/core/lib/json/json.cc
+++ b/src/core/lib/json/json.cc
@@ -23,7 +23,7 @@
#include "src/core/lib/json/json.h"
grpc_json* grpc_json_create(grpc_json_type type) {
- grpc_json* json = (grpc_json*)gpr_zalloc(sizeof(*json));
+ grpc_json* json = static_cast<grpc_json*>(gpr_zalloc(sizeof(*json)));
json->type = type;
return json;
diff --git a/src/core/lib/json/json_reader.cc b/src/core/lib/json/json_reader.cc
index 30039419b1..019214a167 100644
--- a/src/core/lib/json/json_reader.cc
+++ b/src/core/lib/json/json_reader.cc
@@ -138,7 +138,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
case GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL:
case GRPC_JSON_STATE_VALUE_NUMBER_ZERO:
case GRPC_JSON_STATE_VALUE_NUMBER_EPM:
- success = (uint32_t)json_reader_set_number(reader);
+ success = static_cast<uint32_t>(json_reader_set_number(reader));
if (!success) return GRPC_JSON_PARSE_ERROR;
json_reader_string_clear(reader);
reader->state = GRPC_JSON_STATE_VALUE_END;
@@ -173,7 +173,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
} else if ((c == ']') && !reader->in_array) {
return GRPC_JSON_PARSE_ERROR;
}
- success = (uint32_t)json_reader_set_number(reader);
+ success = static_cast<uint32_t>(json_reader_set_number(reader));
if (!success) return GRPC_JSON_PARSE_ERROR;
json_reader_string_clear(reader);
reader->state = GRPC_JSON_STATE_VALUE_END;
@@ -417,8 +417,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) {
} else {
return GRPC_JSON_PARSE_ERROR;
}
- reader->unicode_char = (uint16_t)(reader->unicode_char << 4);
- reader->unicode_char = (uint16_t)(reader->unicode_char | c);
+ reader->unicode_char = static_cast<uint16_t>(reader->unicode_char << 4);
+ reader->unicode_char = static_cast<uint16_t>(reader->unicode_char | c);
switch (reader->state) {
case GRPC_JSON_STATE_STRING_ESCAPE_U1:
@@ -445,9 +445,9 @@ 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 += (uint32_t)(
+ utf32 += static_cast<uint32_t>(
(reader->unicode_high_surrogate - 0xd800) * 0x400);
- utf32 += (uint32_t)(reader->unicode_char - 0xdc00);
+ utf32 += static_cast<uint32_t>(reader->unicode_char - 0xdc00);
json_reader_string_add_utf32(reader, utf32);
reader->unicode_high_surrogate = 0;
} else {
diff --git a/src/core/lib/json/json_string.cc b/src/core/lib/json/json_string.cc
index a339eec81b..dcaf11d0c9 100644
--- a/src/core/lib/json/json_string.cc
+++ b/src/core/lib/json/json_string.cc
@@ -63,19 +63,19 @@ typedef struct {
* bytes at a time (or multiples thereof).
*/
static void json_writer_output_check(void* userdata, size_t needed) {
- json_writer_userdata* state = (json_writer_userdata*)userdata;
+ json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
if (state->free_space >= needed) return;
needed -= state->free_space;
/* Round up by 256 bytes. */
needed = (needed + 0xff) & ~0xffU;
- state->output = (char*)gpr_realloc(state->output, state->allocated + needed);
+ state->output = static_cast<char*>(gpr_realloc(state->output, state->allocated + needed));
state->free_space += needed;
state->allocated += needed;
}
/* These are needed by the writer's implementation. */
static void json_writer_output_char(void* userdata, char c) {
- json_writer_userdata* state = (json_writer_userdata*)userdata;
+ json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
json_writer_output_check(userdata, 1);
state->output[state->string_len++] = c;
state->free_space--;
@@ -83,7 +83,7 @@ static void json_writer_output_char(void* userdata, char c) {
static void json_writer_output_string_with_len(void* userdata, const char* str,
size_t len) {
- json_writer_userdata* state = (json_writer_userdata*)userdata;
+ json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
json_writer_output_check(userdata, len);
memcpy(state->output + state->string_len, str, len);
state->string_len += len;
@@ -99,7 +99,7 @@ static void json_writer_output_string(void* userdata, const char* str) {
* the end of the current string, and advance our output pointer.
*/
static void json_reader_string_clear(void* userdata) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
if (state->string) {
GPR_ASSERT(state->string_ptr < state->input);
*state->string_ptr++ = 0;
@@ -108,10 +108,10 @@ static void json_reader_string_clear(void* userdata) {
}
static void json_reader_string_add_char(void* userdata, uint32_t c) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
GPR_ASSERT(state->string_ptr < state->input);
GPR_ASSERT(c <= 0xff);
- *state->string_ptr++ = (uint8_t)c;
+ *state->string_ptr++ = static_cast<uint8_t>(c);
}
/* We are converting a UTF-32 character into UTF-8 here,
@@ -149,7 +149,7 @@ static void json_reader_string_add_utf32(void* userdata, uint32_t c) {
*/
static uint32_t json_reader_read_char(void* userdata) {
uint32_t r;
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
if (state->remaining_input == 0) return GRPC_JSON_READ_CHAR_EOF;
@@ -168,7 +168,7 @@ static uint32_t json_reader_read_char(void* userdata) {
* our tree-in-progress inside our opaque structure.
*/
static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json* json = grpc_json_create(type);
json->parent = state->current_container;
@@ -183,7 +183,7 @@ static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) {
json->parent->child = json;
}
if (json->parent->type == GRPC_JSON_OBJECT) {
- json->key = (char*)state->key;
+ json->key = reinterpret_cast<char*>(state->key);
}
}
if (!state->top) {
@@ -194,7 +194,7 @@ static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) {
}
static void json_reader_container_begins(void* userdata, grpc_json_type type) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json* container;
GPR_ASSERT(type == GRPC_JSON_ARRAY || type == GRPC_JSON_OBJECT);
@@ -215,7 +215,7 @@ static void json_reader_container_begins(void* userdata, grpc_json_type type) {
*/
static grpc_json_type json_reader_container_ends(void* userdata) {
grpc_json_type container_type = GRPC_JSON_TOP_LEVEL;
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
GPR_ASSERT(state->current_container);
@@ -236,20 +236,20 @@ static grpc_json_type json_reader_container_ends(void* userdata) {
* We'll keep it as a string, and leave it to the caller to evaluate it.
*/
static void json_reader_set_key(void* userdata) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
state->key = state->string;
}
static void json_reader_set_string(void* userdata) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json* json = json_create_and_link(userdata, GRPC_JSON_STRING);
- json->value = (char*)state->string;
+ json->value = reinterpret_cast<char*>(state->string);
}
static int json_reader_set_number(void* userdata) {
- json_reader_userdata* state = (json_reader_userdata*)userdata;
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json* json = json_create_and_link(userdata, GRPC_JSON_NUMBER);
- json->value = (char*)state->string;
+ json->value = reinterpret_cast<char*>(state->string);
return 1;
}
@@ -287,7 +287,7 @@ grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) {
state.top = state.current_container = state.current_value = nullptr;
state.string = state.key = nullptr;
- state.string_ptr = state.input = (uint8_t*)input;
+ state.string_ptr = state.input = reinterpret_cast<uint8_t*>(input);
state.remaining_input = size;
grpc_json_reader_init(&reader, &reader_vtable, &state);
diff --git a/src/core/lib/json/json_writer.cc b/src/core/lib/json/json_writer.cc
index 0b9c7c30ea..df49cbe4dc 100644
--- a/src/core/lib/json/json_writer.cc
+++ b/src/core/lib/json/json_writer.cc
@@ -52,7 +52,7 @@ static void json_writer_output_indent(grpc_json_writer* writer) {
" "
" ";
- unsigned spaces = (unsigned)(writer->depth * writer->indent);
+ unsigned spaces = static_cast<unsigned>(writer->depth * writer->indent);
if (writer->indent == 0) return;
@@ -64,7 +64,7 @@ static void json_writer_output_indent(grpc_json_writer* writer) {
while (spaces >= (sizeof(spacesstr) - 1)) {
json_writer_output_string_with_len(writer, spacesstr,
sizeof(spacesstr) - 1);
- spaces -= (unsigned)(sizeof(spacesstr) - 1);
+ spaces -= static_cast<unsigned>(sizeof(spacesstr) - 1);
}
if (spaces == 0) return;
@@ -100,12 +100,12 @@ static void json_writer_escape_string(grpc_json_writer* writer,
json_writer_output_char(writer, '"');
for (;;) {
- uint8_t c = (uint8_t)*string++;
+ uint8_t c = static_cast<uint8_t>(*string++);
if (c == 0) {
break;
} else if ((c >= 32) && (c <= 126)) {
if ((c == '\\') || (c == '"')) json_writer_output_char(writer, '\\');
- json_writer_output_char(writer, (char)c);
+ json_writer_output_char(writer, static_cast<char>(c));
} else if ((c < 32) || (c == 127)) {
switch (c) {
case '\b':
@@ -146,7 +146,7 @@ static void json_writer_escape_string(grpc_json_writer* writer,
}
for (i = 0; i < extra; i++) {
utf32 <<= 6;
- c = (uint8_t)(*string++);
+ c = static_cast<uint8_t>(*string++);
/* Breaks out and bail on any invalid UTF-8 sequence, including \0. */
if ((c & 0xc0) != 0x80) {
valid = 0;
@@ -179,10 +179,10 @@ static void json_writer_escape_string(grpc_json_writer* writer,
* That range is exactly 20 bits.
*/
utf32 -= 0x10000;
- json_writer_escape_utf16(writer, (uint16_t)(0xd800 | (utf32 >> 10)));
- json_writer_escape_utf16(writer, (uint16_t)(0xdc00 | (utf32 & 0x3ff)));
+ json_writer_escape_utf16(writer, static_cast<uint16_t>(0xd800 | (utf32 >> 10)));
+ json_writer_escape_utf16(writer, static_cast<uint16_t>(0xdc00 | (utf32 & 0x3ff)));
} else {
- json_writer_escape_utf16(writer, (uint16_t)utf32);
+ json_writer_escape_utf16(writer, static_cast<uint16_t>(utf32));
}
}
}