Files
fx/test/ds/strings.c

44 lines
1.1 KiB
C
Raw Permalink Normal View History

2026-03-16 10:35:43 +00:00
#include <fx/core/stringstream.h>
#include <fx/ds/string.h>
2024-10-24 21:33:19 +01:00
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("-------------\n");
2026-03-16 10:35:43 +00:00
fx_string *str = fx_string_create_from_cstr("Hello, world!\n");
printf("%s\n", fx_string_ptr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
2026-03-16 10:35:43 +00:00
fx_string_insert_cstr(str, "WOW!", 4);
2024-10-24 21:33:19 +01:00
printf("-------------\n");
2026-03-16 10:35:43 +00:00
printf("%s\n", fx_string_ptr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
2026-03-16 10:35:43 +00:00
fx_string_replace(str, 4, 4, "+");
printf("-------------\n");
2026-03-16 10:35:43 +00:00
printf("%s\n", fx_string_ptr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
printf("-------------\n");
2024-10-24 21:33:19 +01:00
2026-03-16 10:35:43 +00:00
fx_string_unref(str);
2024-10-24 21:33:19 +01:00
2026-03-16 10:35:43 +00:00
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);
2025-10-24 12:51:54 +01:00
2026-03-16 10:35:43 +00:00
char *s = fx_stringstream_steal(strv);
fx_stringstream_unref(strv);
2024-10-24 21:33:19 +01:00
printf("%s\n", s);
free(s);
return 0;
}