test: update write_string function references
This commit is contained in:
@@ -158,7 +158,7 @@ void test_stringstream_1(CuTest *tc)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
|
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);
|
fx_stream_write_fmt(s, NULL, "(%d + %.1f)", 32, 2.3);
|
||||||
|
|
||||||
char *end = fx_stringstream_steal(s);
|
char *end = fx_stringstream_steal(s);
|
||||||
@@ -172,14 +172,14 @@ void test_stringstream_2(CuTest *tc)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
|
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_push_indent(s, 1);
|
||||||
|
|
||||||
fx_stream_write_string(s, "a = 32,\n", NULL);
|
fx_stream_write_cstr(s, "a = 32,\n", NULL);
|
||||||
fx_stream_write_string(s, "b = 64\n", NULL);
|
fx_stream_write_cstr(s, "b = 64\n", NULL);
|
||||||
|
|
||||||
fx_stream_pop_indent(s);
|
fx_stream_pop_indent(s);
|
||||||
fx_stream_write_string(s, "}", NULL);
|
fx_stream_write_cstr(s, "}", NULL);
|
||||||
|
|
||||||
char *str = fx_stringstream_steal(s);
|
char *str = fx_stringstream_steal(s);
|
||||||
fx_stringstream_unref(s);
|
fx_stringstream_unref(s);
|
||||||
|
|||||||
+3
-3
@@ -29,9 +29,9 @@ int main(void)
|
|||||||
fx_string_unref(str);
|
fx_string_unref(str);
|
||||||
|
|
||||||
fx_stringstream *strv = fx_stringstream_create();
|
fx_stringstream *strv = fx_stringstream_create();
|
||||||
fx_stream_write_string(strv, "Hello", NULL);
|
fx_stream_write_cstr(strv, "Hello", NULL);
|
||||||
fx_stream_write_string(strv, ", world", NULL);
|
fx_stream_write_cstr(strv, ", world", NULL);
|
||||||
fx_stream_write_string(strv, "!", NULL);
|
fx_stream_write_cstr(strv, "!", NULL);
|
||||||
|
|
||||||
char *s = fx_stringstream_steal(strv);
|
char *s = fx_stringstream_steal(strv);
|
||||||
fx_stringstream_unref(strv);
|
fx_stringstream_unref(strv);
|
||||||
|
|||||||
+30
-30
@@ -10,7 +10,7 @@ void write_tagged_value(fx_object *data);
|
|||||||
|
|
||||||
void write_raw_string(const fx_string *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);
|
const fx_iterator *it = fx_iterator_cbegin(data);
|
||||||
fx_foreach_c(fx_wchar, c, it)
|
fx_foreach_c(fx_wchar, c, it)
|
||||||
@@ -30,52 +30,52 @@ void write_raw_string(const fx_string *data)
|
|||||||
}
|
}
|
||||||
fx_iterator_unref(it);
|
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)
|
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);
|
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)
|
void write_tagged_integer(fx_number *data)
|
||||||
{
|
{
|
||||||
fx_stream_write_string(
|
fx_stream_write_cstr(
|
||||||
fx_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL);
|
fx_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL);
|
||||||
|
|
||||||
if (fx_number_is_inf_positive(data)) {
|
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)) {
|
} 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)) {
|
} 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)) {
|
} 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 {
|
} else {
|
||||||
fx_stream_write_fmt(
|
fx_stream_write_fmt(
|
||||||
fx_stdout, NULL, "%lld", fx_number_get_longlong(data), NULL);
|
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)
|
void write_tagged_float(fx_number *data)
|
||||||
{
|
{
|
||||||
fx_stream_write_string(
|
fx_stream_write_cstr(
|
||||||
fx_stdout, "{ \"type\": \"float\", \"value\": \"", NULL);
|
fx_stdout, "{ \"type\": \"float\", \"value\": \"", NULL);
|
||||||
|
|
||||||
if (fx_number_is_inf_positive(data)) {
|
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)) {
|
} 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)) {
|
} 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)) {
|
} 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 {
|
} else {
|
||||||
double v = fx_number_get_double(data);
|
double v = fx_number_get_double(data);
|
||||||
if ((v <= 0.00000001 && v > 0) || (v >= -0.00000001 && v < 0)
|
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)
|
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 has_time = fx_datetime_has_time(data);
|
||||||
bool localtime = fx_datetime_is_localtime(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) {
|
if (has_date && has_time) {
|
||||||
fx_stream_write_string(
|
fx_stream_write_cstr(
|
||||||
fx_stdout, localtime ? "datetime-local" : "datetime", NULL);
|
fx_stdout, localtime ? "datetime-local" : "datetime", NULL);
|
||||||
} else if (has_date) {
|
} else if (has_date) {
|
||||||
fx_stream_write_string(
|
fx_stream_write_cstr(
|
||||||
fx_stdout, localtime ? "date-local" : "date", NULL);
|
fx_stdout, localtime ? "date-local" : "date", NULL);
|
||||||
} else if (has_time) {
|
} else if (has_time) {
|
||||||
fx_stream_write_string(
|
fx_stream_write_cstr(
|
||||||
fx_stdout, localtime ? "time-local" : "time", NULL);
|
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_string *new_data = fx_string_create();
|
||||||
fx_datetime_to_string(data, FX_DATETIME_FORMAT_RFC3339, new_data);
|
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);
|
fx_string_unref(new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_tagged_dict(fx_dict *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;
|
int i = 0;
|
||||||
|
|
||||||
@@ -137,35 +137,35 @@ void write_tagged_dict(fx_dict *data)
|
|||||||
fx_foreach(fx_dict_item *, item, it)
|
fx_foreach(fx_dict_item *, item, it)
|
||||||
{
|
{
|
||||||
if (i++ > 0) {
|
if (i++ > 0) {
|
||||||
fx_stream_write_string(fx_stdout, ", ", NULL);
|
fx_stream_write_cstr(fx_stdout, ", ", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
write_raw_string(item->key);
|
write_raw_string(item->key);
|
||||||
fx_stream_write_string(fx_stdout, ": ", NULL);
|
fx_stream_write_cstr(fx_stdout, ": ", NULL);
|
||||||
write_tagged_value(item->value);
|
write_tagged_value(item->value);
|
||||||
}
|
}
|
||||||
fx_iterator_unref(it);
|
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)
|
void write_tagged_array(fx_array *data)
|
||||||
{
|
{
|
||||||
fx_stream_write_string(fx_stdout, "[ ", NULL);
|
fx_stream_write_cstr(fx_stdout, "[ ", NULL);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
fx_iterator *it = fx_iterator_begin(data);
|
fx_iterator *it = fx_iterator_begin(data);
|
||||||
fx_foreach(fx_object *, obj, it)
|
fx_foreach(fx_object *, obj, it)
|
||||||
{
|
{
|
||||||
if (i++ > 0) {
|
if (i++ > 0) {
|
||||||
fx_stream_write_string(fx_stdout, ", ", NULL);
|
fx_stream_write_cstr(fx_stdout, ", ", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
write_tagged_value(obj);
|
write_tagged_value(obj);
|
||||||
}
|
}
|
||||||
fx_iterator_unref(it);
|
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)
|
void write_tagged_value(fx_object *data)
|
||||||
|
|||||||
Reference in New Issue
Block a user