test: update write_string function references

This commit is contained in:
2026-04-20 22:05:42 +01:00
parent 5646c8c2b8
commit cb39baa233
3 changed files with 38 additions and 38 deletions
+5 -5
View File
@@ -158,7 +158,7 @@ void test_stringstream_1(CuTest *tc)
char buf[1024];
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
fx_stream_write_string(s, "hello", NULL);
fx_stream_write_cstr(s, "hello", NULL);
fx_stream_write_fmt(s, NULL, "(%d + %.1f)", 32, 2.3);
char *end = fx_stringstream_steal(s);
@@ -172,14 +172,14 @@ void test_stringstream_2(CuTest *tc)
char buf[1024];
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
fx_stream_write_string(s, "{\n", NULL);
fx_stream_write_cstr(s, "{\n", NULL);
fx_stream_push_indent(s, 1);
fx_stream_write_string(s, "a = 32,\n", NULL);
fx_stream_write_string(s, "b = 64\n", NULL);
fx_stream_write_cstr(s, "a = 32,\n", NULL);
fx_stream_write_cstr(s, "b = 64\n", NULL);
fx_stream_pop_indent(s);
fx_stream_write_string(s, "}", NULL);
fx_stream_write_cstr(s, "}", NULL);
char *str = fx_stringstream_steal(s);
fx_stringstream_unref(s);
+3 -3
View File
@@ -29,9 +29,9 @@ int main(void)
fx_string_unref(str);
fx_stringstream *strv = fx_stringstream_create();
fx_stream_write_string(strv, "Hello", NULL);
fx_stream_write_string(strv, ", world", NULL);
fx_stream_write_string(strv, "!", NULL);
fx_stream_write_cstr(strv, "Hello", NULL);
fx_stream_write_cstr(strv, ", world", NULL);
fx_stream_write_cstr(strv, "!", NULL);
char *s = fx_stringstream_steal(strv);
fx_stringstream_unref(strv);
+30 -30
View File
@@ -10,7 +10,7 @@ void write_tagged_value(fx_object *data);
void write_raw_string(const fx_string *data)
{
fx_stream_write_string(fx_stdout, "\"", NULL);
fx_stream_write_cstr(fx_stdout, "\"", NULL);
const fx_iterator *it = fx_iterator_cbegin(data);
fx_foreach_c(fx_wchar, c, it)
@@ -30,52 +30,52 @@ void write_raw_string(const fx_string *data)
}
fx_iterator_unref(it);
fx_stream_write_string(fx_stdout, "\"", NULL);
fx_stream_write_cstr(fx_stdout, "\"", NULL);
}
void write_tagged_string(fx_string *data)
{
fx_stream_write_string(fx_stdout, "{ \"type\": \"string\", \"value\": ", NULL);
fx_stream_write_cstr(fx_stdout, "{ \"type\": \"string\", \"value\": ", NULL);
write_raw_string(data);
fx_stream_write_string(fx_stdout, " }", NULL);
fx_stream_write_cstr(fx_stdout, " }", NULL);
}
void write_tagged_integer(fx_number *data)
{
fx_stream_write_string(
fx_stream_write_cstr(
fx_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL);
if (fx_number_is_inf_positive(data)) {
fx_stream_write_string(fx_stdout, "inf", NULL);
fx_stream_write_cstr(fx_stdout, "inf", NULL);
} else if (fx_number_is_inf_negative(data)) {
fx_stream_write_string(fx_stdout, "-inf", NULL);
fx_stream_write_cstr(fx_stdout, "-inf", NULL);
} else if (fx_number_is_nan_positive(data)) {
fx_stream_write_string(fx_stdout, "nan", NULL);
fx_stream_write_cstr(fx_stdout, "nan", NULL);
} else if (fx_number_is_nan_negative(data)) {
fx_stream_write_string(fx_stdout, "-nan", NULL);
fx_stream_write_cstr(fx_stdout, "-nan", NULL);
} else {
fx_stream_write_fmt(
fx_stdout, NULL, "%lld", fx_number_get_longlong(data), NULL);
}
fx_stream_write_string(fx_stdout, "\" }", NULL);
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
}
void write_tagged_float(fx_number *data)
{
fx_stream_write_string(
fx_stream_write_cstr(
fx_stdout, "{ \"type\": \"float\", \"value\": \"", NULL);
if (fx_number_is_inf_positive(data)) {
fx_stream_write_string(fx_stdout, "inf", NULL);
fx_stream_write_cstr(fx_stdout, "inf", NULL);
} else if (fx_number_is_inf_negative(data)) {
fx_stream_write_string(fx_stdout, "-inf", NULL);
fx_stream_write_cstr(fx_stdout, "-inf", NULL);
} else if (fx_number_is_nan_positive(data)) {
fx_stream_write_string(fx_stdout, "nan", NULL);
fx_stream_write_cstr(fx_stdout, "nan", NULL);
} else if (fx_number_is_nan_negative(data)) {
fx_stream_write_string(fx_stdout, "-nan", NULL);
fx_stream_write_cstr(fx_stdout, "-nan", NULL);
} else {
double v = fx_number_get_double(data);
if ((v <= 0.00000001 && v > 0) || (v >= -0.00000001 && v < 0)
@@ -86,7 +86,7 @@ void write_tagged_float(fx_number *data)
}
}
fx_stream_write_string(fx_stdout, "\" }", NULL);
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
}
void write_tagged_bool(fx_number *data)
@@ -103,33 +103,33 @@ void write_tagged_datetime(fx_datetime *data)
bool has_time = fx_datetime_has_time(data);
bool localtime = fx_datetime_is_localtime(data);
fx_stream_write_string(fx_stdout, "{ \"type\": \"", NULL);
fx_stream_write_cstr(fx_stdout, "{ \"type\": \"", NULL);
if (has_date && has_time) {
fx_stream_write_string(
fx_stream_write_cstr(
fx_stdout, localtime ? "datetime-local" : "datetime", NULL);
} else if (has_date) {
fx_stream_write_string(
fx_stream_write_cstr(
fx_stdout, localtime ? "date-local" : "date", NULL);
} else if (has_time) {
fx_stream_write_string(
fx_stream_write_cstr(
fx_stdout, localtime ? "time-local" : "time", NULL);
}
fx_stream_write_string(fx_stdout, "\", \"value\": \"", NULL);
fx_stream_write_cstr(fx_stdout, "\", \"value\": \"", NULL);
fx_string *new_data = fx_string_create();
fx_datetime_to_string(data, FX_DATETIME_FORMAT_RFC3339, new_data);
fx_stream_write_string(fx_stdout, fx_string_ptr(new_data), NULL);
fx_stream_write_cstr(fx_stdout, fx_string_ptr(new_data), NULL);
fx_stream_write_string(fx_stdout, "\" }", NULL);
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
fx_string_unref(new_data);
}
void write_tagged_dict(fx_dict *data)
{
fx_stream_write_string(fx_stdout, "{ ", NULL);
fx_stream_write_cstr(fx_stdout, "{ ", NULL);
int i = 0;
@@ -137,35 +137,35 @@ void write_tagged_dict(fx_dict *data)
fx_foreach(fx_dict_item *, item, it)
{
if (i++ > 0) {
fx_stream_write_string(fx_stdout, ", ", NULL);
fx_stream_write_cstr(fx_stdout, ", ", NULL);
}
write_raw_string(item->key);
fx_stream_write_string(fx_stdout, ": ", NULL);
fx_stream_write_cstr(fx_stdout, ": ", NULL);
write_tagged_value(item->value);
}
fx_iterator_unref(it);
fx_stream_write_string(fx_stdout, " }", NULL);
fx_stream_write_cstr(fx_stdout, " }", NULL);
}
void write_tagged_array(fx_array *data)
{
fx_stream_write_string(fx_stdout, "[ ", NULL);
fx_stream_write_cstr(fx_stdout, "[ ", NULL);
int i = 0;
fx_iterator *it = fx_iterator_begin(data);
fx_foreach(fx_object *, obj, it)
{
if (i++ > 0) {
fx_stream_write_string(fx_stdout, ", ", NULL);
fx_stream_write_cstr(fx_stdout, ", ", NULL);
}
write_tagged_value(obj);
}
fx_iterator_unref(it);
fx_stream_write_string(fx_stdout, " ]", NULL);
fx_stream_write_cstr(fx_stdout, " ]", NULL);
}
void write_tagged_value(fx_object *data)