From ccf5e49b969c7643cd67ac678a7f13f4639db745 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov <0x7fffff@guattari.ru> Date: Sun, 7 Aug 2022 09:51:58 +0400 Subject: Refactor --- source/kit/input_stream.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/source/kit/input_stream.c b/source/kit/input_stream.c index 64a305e..89be44c 100644 --- a/source/kit/input_stream.c +++ b/source/kit/input_stream.c @@ -2,7 +2,7 @@ #include -enum { input_stream_cstr }; +enum { input_stream_str }; typedef struct { ptrdiff_t type; @@ -13,9 +13,9 @@ typedef struct { ptrdiff_t type; kit_allocator_t alloc; kit_str_t string; -} kit_is_state_cstr_t; +} kit_is_state_str_t; -static _Bool check_type(void *state, ptrdiff_t type) { +static int check_type(void *state, ptrdiff_t type) { kit_is_state_basic_t *basic = (kit_is_state_basic_t *) state; return basic != NULL && basic->type == type; } @@ -26,14 +26,14 @@ static ptrdiff_t min(ptrdiff_t a, ptrdiff_t b) { return b; } -static ptrdiff_t read_cstr(void *state, kit_out_str_t destination) { - if (!check_type(state, input_stream_cstr)) +static ptrdiff_t read_str(void *state, kit_out_str_t destination) { + if (!check_type(state, input_stream_str)) return 0; - kit_is_state_cstr_t *cstr = (kit_is_state_cstr_t *) state; - ptrdiff_t size = min(destination.size, cstr->string.size); - memcpy(destination.values, cstr->string.values, size); - cstr->string.values += size; - cstr->string.size -= size; + kit_is_state_str_t *str = (kit_is_state_str_t *) state; + ptrdiff_t size = min(destination.size, str->string.size); + memcpy(destination.values, str->string.values, size); + str->string.values += size; + str->string.size -= size; return size; } @@ -41,15 +41,15 @@ kit_is_handle_t kit_is_wrap_string(kit_str_t string, kit_allocator_t alloc) { kit_is_handle_t in; memset(&in, 0, sizeof in); - kit_is_state_cstr_t *state = (kit_is_state_cstr_t *) alloc.allocate( - alloc.state, sizeof(kit_is_state_cstr_t)); + kit_is_state_str_t *state = (kit_is_state_str_t *) alloc.allocate( + alloc.state, sizeof(kit_is_state_str_t)); if (state != NULL) { memset(state, 0, sizeof *state); - state->type = input_stream_cstr; + state->type = input_stream_str; state->string = string; state->alloc = alloc; in.state = state; - in.read = read_cstr; + in.read = read_str; } return in; } -- cgit v1.2.3