ds: string: add verbs to function names

This commit is contained in:
2026-04-20 22:03:11 +01:00
parent c39f50a0ee
commit 321622ac16
6 changed files with 133 additions and 51 deletions
+3 -3
View File
@@ -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); struct fx_array_p *array = fx_object_get_private(obj, FX_TYPE_ARRAY);
if (!array->ar_len) { if (!array->ar_len) {
fx_stream_write_string(out, "[]", NULL); fx_stream_write_cstr(out, "[]", NULL);
return; return;
} }
fx_stream_write_string(out, "[\n", NULL); fx_stream_write_cstr(out, "[\n", NULL);
fx_stream_push_indent(out, 1); fx_stream_push_indent(out, 1);
size_t len = array_size(array); 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) { if (i < len - 1) {
fx_stream_write_string(out, ",", NULL); fx_stream_write_cstr(out, ",", NULL);
} }
fx_stream_write_char(out, '\n'); fx_stream_write_char(out, '\n');
+5 -5
View File
@@ -147,7 +147,7 @@ static fx_object *dict_at(const struct fx_dict_p *dict, const char *key)
struct fx_dict_bucket_item *item struct fx_dict_bucket_item *item
= fx_unbox(struct fx_dict_bucket_item, entry, bi_entry); = 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; 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); struct fx_dict_p *dict = fx_object_get_private(obj, FX_TYPE_DICT);
if (dict_is_empty(dict)) { if (dict_is_empty(dict)) {
fx_stream_write_string(out, "{}", NULL); fx_stream_write_cstr(out, "{}", NULL);
return; return;
} }
fx_stream_write_string(out, "{\n", NULL); fx_stream_write_cstr(out, "{\n", NULL);
fx_stream_push_indent(out, 1); fx_stream_push_indent(out, 1);
size_t len = dict_get_size(dict); 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); struct fx_dict_bucket_item, entry, bi_entry);
fx_object_to_string(item->bi_str, out); 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( bool is_string = fx_object_is_type(
item->bi_value, FX_TYPE_STRING); 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) { if (i < len - 1) {
fx_stream_write_string(out, ",", NULL); fx_stream_write_cstr(out, ",", NULL);
} }
fx_stream_write_char(out, '\n'); fx_stream_write_char(out, '\n');
+8 -4
View File
@@ -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 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_reserve(fx_string *str, size_t capacity);
FX_API fx_status fx_string_replace( 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(fx_string *str, const char *new_data);
FX_API fx_status fx_string_replace_all_with_stringstream( 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_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_transform(fx_string *str, int (*transformer)(int));
FX_API fx_status fx_string_trim(fx_string *str); 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); 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); return fx_string_transform(str, tolower);
} }
+114 -36
View File
@@ -532,110 +532,188 @@ static void print_inf(const struct fx_number_p *n, fx_stream *out)
{ {
switch (n->n_type) { switch (n->n_type) {
case FX_NUMBER_INT8: 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; break;
case FX_NUMBER_INT16: 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; break;
case FX_NUMBER_INT32: 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; break;
case FX_NUMBER_INT64: 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; break;
case FX_NUMBER_FLOAT32: case FX_NUMBER_FLOAT32:
fx_stream_write_string( fx_stream_write_cstr(
out, n->n_value.v_float32 < 0 ? "-" : "", NULL); out,
n->n_value.v_float32 < 0 ? "-" : "",
NULL);
break; break;
case FX_NUMBER_FLOAT64: case FX_NUMBER_FLOAT64:
fx_stream_write_string( fx_stream_write_cstr(
out, n->n_value.v_float64 < 0 ? "-" : "", NULL); out,
n->n_value.v_float64 < 0 ? "-" : "",
NULL);
break; break;
case FX_NUMBER_CHAR: 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; break;
case FX_NUMBER_SHORT: 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; break;
case FX_NUMBER_INT: 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; break;
case FX_NUMBER_LONG: 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; break;
case FX_NUMBER_LONGLONG: case FX_NUMBER_LONGLONG:
fx_stream_write_string( fx_stream_write_cstr(
out, n->n_value.v_longlong < 0 ? "-" : "", NULL); out,
n->n_value.v_longlong < 0 ? "-" : "",
NULL);
break; break;
case FX_NUMBER_FLOAT: 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; break;
case FX_NUMBER_DOUBLE: 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; break;
case FX_NUMBER_SIZE_T: 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; break;
default: default:
break; 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) static void print_nan(const struct fx_number_p *n, fx_stream *out)
{ {
switch (n->n_type) { switch (n->n_type) {
case FX_NUMBER_INT8: 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; break;
case FX_NUMBER_INT16: 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; break;
case FX_NUMBER_INT32: 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; break;
case FX_NUMBER_INT64: 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; break;
case FX_NUMBER_FLOAT32: case FX_NUMBER_FLOAT32:
fx_stream_write_string( fx_stream_write_cstr(
out, n->n_value.v_float32 < 0 ? "-" : "", NULL); out,
n->n_value.v_float32 < 0 ? "-" : "",
NULL);
break; break;
case FX_NUMBER_FLOAT64: case FX_NUMBER_FLOAT64:
fx_stream_write_string( fx_stream_write_cstr(
out, n->n_value.v_float64 < 0 ? "-" : "", NULL); out,
n->n_value.v_float64 < 0 ? "-" : "",
NULL);
break; break;
case FX_NUMBER_CHAR: 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; break;
case FX_NUMBER_SHORT: 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; break;
case FX_NUMBER_INT: 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; break;
case FX_NUMBER_LONG: 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; break;
case FX_NUMBER_LONGLONG: case FX_NUMBER_LONGLONG:
fx_stream_write_string( fx_stream_write_cstr(
out, n->n_value.v_longlong < 0 ? "-" : "", NULL); out,
n->n_value.v_longlong < 0 ? "-" : "",
NULL);
break; break;
case FX_NUMBER_FLOAT: 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; break;
case FX_NUMBER_DOUBLE: 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; break;
case FX_NUMBER_SIZE_T: 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; break;
default: default:
break; break;
} }
fx_stream_write_string(out, "NaN", NULL); fx_stream_write_cstr(out, "NaN", NULL);
} }
/*** PUBLIC FUNCTIONS *********************************************************/ /*** PUBLIC FUNCTIONS *********************************************************/
+1 -1
View File
@@ -1297,7 +1297,7 @@ void fx_string_pop_back(fx_string *str)
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRING, string_pop_back, 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); FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRING, string_ptr, str);
} }
+2 -2
View File
@@ -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) 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 ********************************************************/ /*** VIRTUAL FUNCTIONS ********************************************************/
@@ -207,7 +207,7 @@ static void uuid_to_string(const fx_object *uuid, fx_stream *out)
{ {
char str[FX_UUID_STRING_MAX]; char str[FX_UUID_STRING_MAX];
fx_uuid_to_cstr(uuid, str); fx_uuid_to_cstr(uuid, str);
fx_stream_write_string(out, str, NULL); fx_stream_write_cstr(out, str, NULL);
} }
/*** CLASS DEFINITION *********************************************************/ /*** CLASS DEFINITION *********************************************************/