diff --git a/ds/array.c b/ds/array.c index b0119e8..d5e7fe9 100644 --- a/ds/array.c +++ b/ds/array.c @@ -323,11 +323,11 @@ static void array_to_string(const fx_object *obj, fx_stream *out) struct fx_array_p *array = fx_object_get_private(obj, FX_TYPE_ARRAY); if (!array->ar_len) { - fx_stream_write_string(out, "[]", NULL); + fx_stream_write_cstr(out, "[]", NULL); return; } - fx_stream_write_string(out, "[\n", NULL); + fx_stream_write_cstr(out, "[\n", NULL); fx_stream_push_indent(out, 1); size_t len = array_size(array); @@ -347,7 +347,7 @@ static void array_to_string(const fx_object *obj, fx_stream *out) } if (i < len - 1) { - fx_stream_write_string(out, ",", NULL); + fx_stream_write_cstr(out, ",", NULL); } fx_stream_write_char(out, '\n'); diff --git a/ds/dict.c b/ds/dict.c index 37d1bed..f9f9af7 100644 --- a/ds/dict.c +++ b/ds/dict.c @@ -147,7 +147,7 @@ static fx_object *dict_at(const struct fx_dict_p *dict, const char *key) struct fx_dict_bucket_item *item = fx_unbox(struct fx_dict_bucket_item, entry, bi_entry); - if (!strcmp(fx_string_ptr(item->bi_str), key)) { + if (!strcmp(fx_string_get_cstr(item->bi_str), key)) { return item->bi_value; } @@ -425,11 +425,11 @@ static void dict_to_string(const fx_object *obj, fx_stream *out) struct fx_dict_p *dict = fx_object_get_private(obj, FX_TYPE_DICT); if (dict_is_empty(dict)) { - fx_stream_write_string(out, "{}", NULL); + fx_stream_write_cstr(out, "{}", NULL); return; } - fx_stream_write_string(out, "{\n", NULL); + fx_stream_write_cstr(out, "{\n", NULL); fx_stream_push_indent(out, 1); size_t len = dict_get_size(dict); @@ -446,7 +446,7 @@ static void dict_to_string(const fx_object *obj, fx_stream *out) struct fx_dict_bucket_item, entry, bi_entry); fx_object_to_string(item->bi_str, out); - fx_stream_write_string(out, ": ", NULL); + fx_stream_write_cstr(out, ": ", NULL); bool is_string = fx_object_is_type( item->bi_value, FX_TYPE_STRING); @@ -462,7 +462,7 @@ static void dict_to_string(const fx_object *obj, fx_stream *out) } if (i < len - 1) { - fx_stream_write_string(out, ",", NULL); + fx_stream_write_cstr(out, ",", NULL); } fx_stream_write_char(out, '\n'); diff --git a/ds/include/fx/ds/string.h b/ds/include/fx/ds/string.h index e024a98..6ca2ef7 100644 --- a/ds/include/fx/ds/string.h +++ b/ds/include/fx/ds/string.h @@ -52,18 +52,22 @@ FX_API fx_string *fx_string_duplicate(const fx_string *str); FX_API char *fx_string_steal(fx_string *str); FX_API fx_status fx_string_reserve(fx_string *str, size_t capacity); FX_API fx_status fx_string_replace( - fx_string *str, size_t start, size_t length, const char *new_data); + fx_string *str, + size_t start, + size_t length, + const char *new_data); FX_API fx_status fx_string_replace_all(fx_string *str, const char *new_data); FX_API fx_status fx_string_replace_all_with_stringstream( - fx_string *str, const fx_stringstream *new_data); + fx_string *str, + const fx_stringstream *new_data); FX_API fx_status fx_string_remove(fx_string *str, size_t start, size_t length); FX_API fx_status fx_string_transform(fx_string *str, int (*transformer)(int)); FX_API fx_status fx_string_trim(fx_string *str); -static inline fx_status fx_string_toupper(fx_string *str) +static inline fx_status fx_string_transform_uppercase(fx_string *str) { return fx_string_transform(str, toupper); } -static inline fx_status fx_string_tolower(fx_string *str) +static inline fx_status fx_string_transform_lowercase(fx_string *str) { return fx_string_transform(str, tolower); } diff --git a/ds/number.c b/ds/number.c index d3f9172..26012a0 100644 --- a/ds/number.c +++ b/ds/number.c @@ -532,110 +532,188 @@ static void print_inf(const struct fx_number_p *n, fx_stream *out) { switch (n->n_type) { case FX_NUMBER_INT8: - fx_stream_write_string(out, n->n_value.v_int8 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int8 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_INT16: - fx_stream_write_string(out, n->n_value.v_int16 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int16 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_INT32: - fx_stream_write_string(out, n->n_value.v_int32 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int32 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_INT64: - fx_stream_write_string(out, n->n_value.v_int64 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int64 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_FLOAT32: - fx_stream_write_string( - out, n->n_value.v_float32 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_float32 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_FLOAT64: - fx_stream_write_string( - out, n->n_value.v_float64 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_float64 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_CHAR: - fx_stream_write_string(out, n->n_value.v_char < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_char < 0 ? "-" : "", + NULL); break; case FX_NUMBER_SHORT: - fx_stream_write_string(out, n->n_value.v_short < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_short < 0 ? "-" : "", + NULL); break; case FX_NUMBER_INT: - fx_stream_write_string(out, n->n_value.v_int < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int < 0 ? "-" : "", + NULL); break; case FX_NUMBER_LONG: - fx_stream_write_string(out, n->n_value.v_long < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_long < 0 ? "-" : "", + NULL); break; case FX_NUMBER_LONGLONG: - fx_stream_write_string( - out, n->n_value.v_longlong < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_longlong < 0 ? "-" : "", + NULL); break; case FX_NUMBER_FLOAT: - fx_stream_write_string(out, n->n_value.v_float < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_float < 0 ? "-" : "", + NULL); break; case FX_NUMBER_DOUBLE: - fx_stream_write_string(out, n->n_value.v_double < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_double < 0 ? "-" : "", + NULL); break; case FX_NUMBER_SIZE_T: - fx_stream_write_string(out, n->n_value.v_size_t < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_size_t < 0 ? "-" : "", + NULL); break; default: break; } - fx_stream_write_string(out, "INF", NULL); + fx_stream_write_cstr(out, "INF", NULL); } static void print_nan(const struct fx_number_p *n, fx_stream *out) { switch (n->n_type) { case FX_NUMBER_INT8: - fx_stream_write_string(out, n->n_value.v_int8 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int8 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_INT16: - fx_stream_write_string(out, n->n_value.v_int16 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int16 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_INT32: - fx_stream_write_string(out, n->n_value.v_int32 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int32 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_INT64: - fx_stream_write_string(out, n->n_value.v_int64 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int64 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_FLOAT32: - fx_stream_write_string( - out, n->n_value.v_float32 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_float32 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_FLOAT64: - fx_stream_write_string( - out, n->n_value.v_float64 < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_float64 < 0 ? "-" : "", + NULL); break; case FX_NUMBER_CHAR: - fx_stream_write_string(out, n->n_value.v_char < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_char < 0 ? "-" : "", + NULL); break; case FX_NUMBER_SHORT: - fx_stream_write_string(out, n->n_value.v_short < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_short < 0 ? "-" : "", + NULL); break; case FX_NUMBER_INT: - fx_stream_write_string(out, n->n_value.v_int < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_int < 0 ? "-" : "", + NULL); break; case FX_NUMBER_LONG: - fx_stream_write_string(out, n->n_value.v_long < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_long < 0 ? "-" : "", + NULL); break; case FX_NUMBER_LONGLONG: - fx_stream_write_string( - out, n->n_value.v_longlong < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_longlong < 0 ? "-" : "", + NULL); break; case FX_NUMBER_FLOAT: - fx_stream_write_string(out, n->n_value.v_float < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_float < 0 ? "-" : "", + NULL); break; case FX_NUMBER_DOUBLE: - fx_stream_write_string(out, n->n_value.v_double < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_double < 0 ? "-" : "", + NULL); break; case FX_NUMBER_SIZE_T: - fx_stream_write_string(out, n->n_value.v_size_t < 0 ? "-" : "", NULL); + fx_stream_write_cstr( + out, + n->n_value.v_size_t < 0 ? "-" : "", + NULL); break; default: break; } - fx_stream_write_string(out, "NaN", NULL); + fx_stream_write_cstr(out, "NaN", NULL); } /*** PUBLIC FUNCTIONS *********************************************************/ diff --git a/ds/string.c b/ds/string.c index d29c190..f856d48 100644 --- a/ds/string.c +++ b/ds/string.c @@ -1297,7 +1297,7 @@ void fx_string_pop_back(fx_string *str) FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRING, string_pop_back, str); } -const char *fx_string_ptr(const fx_string *str) +const char *fx_string_get_cstr(const fx_string *str) { FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRING, string_ptr, str); } diff --git a/ds/uuid.c b/ds/uuid.c index 4be30f8..1069c0b 100644 --- a/ds/uuid.c +++ b/ds/uuid.c @@ -188,7 +188,7 @@ fx_uuid *fx_uuid_create_from_uuid_bytes(const union fx_uuid_bytes *bytes) fx_uuid *fx_uuid_create_from_string(const fx_string *string) { - return fx_uuid_create_from_cstr(fx_string_ptr(string)); + return fx_uuid_create_from_cstr(fx_string_get_cstr(string)); } /*** VIRTUAL FUNCTIONS ********************************************************/ @@ -207,7 +207,7 @@ static void uuid_to_string(const fx_object *uuid, fx_stream *out) { char str[FX_UUID_STRING_MAX]; fx_uuid_to_cstr(uuid, str); - fx_stream_write_string(out, str, NULL); + fx_stream_write_cstr(out, str, NULL); } /*** CLASS DEFINITION *********************************************************/