object: unify stringstream functionality

This commit is contained in:
2025-02-10 13:59:06 +00:00
parent 5c0df60dab
commit 9add587ddd
5 changed files with 41 additions and 190 deletions

View File

@@ -18,13 +18,6 @@ typedef enum b_strlen_flags {
B_STRLEN_IGNORE_MOD = 0x02u,
} b_strlen_flags;
typedef struct b_strv_builder {
char *strv_buf;
size_t strv_len;
size_t strv_max;
unsigned char strv_alloc;
} b_strv_builder;
BLUE_API b_string *b_string_create(void);
BLUE_API b_string *b_string_create_from_cstr(const char *s);
BLUE_API b_string *b_string_create_from_c(char c, size_t count);
@@ -60,17 +53,6 @@ BLUE_API size_t b_string_get_capacity(const b_string *str);
BLUE_API const char *b_string_ptr(const b_string *str);
BLUE_API void b_strv_builder_begin(b_strv_builder *strv, char *buf, size_t max);
BLUE_API void b_strv_builder_begin_dynamic(b_strv_builder *strv);
BLUE_API b_status b_strv_builder_add(b_strv_builder *strv, const char *str);
BLUE_API b_status b_strv_builder_addf(b_strv_builder *strv, const char *format, ...);
BLUE_API b_status b_strv_builder_addv(b_strv_builder *strv, const char **strs);
BLUE_API b_status b_strv_builder_addvl(
b_strv_builder *strv, const char **strs, size_t count);
BLUE_API b_status b_strv_builder_add_many(b_strv_builder *strv, ...);
BLUE_API char *b_strv_builder_end(b_strv_builder *strv);
BLUE_API char *b_strdup(const char *s);
BLUE_API size_t b_strlen(const char *s, b_strlen_flags flags);

View File

@@ -1,25 +0,0 @@
#ifndef BLUELIB_STRING_FORMATTER_H
#define BLUELIB_STRING_FORMATTER_H
#include <blue/object/string.h>
#include <stdarg.h>
typedef struct b_stringstream b_stringstream;
BLUE_API b_stringstream *b_stringstream_create(void);
BLUE_API b_string *b_stringstream_end(b_stringstream *f);
BLUE_API void b_stringstream_destroy(b_stringstream *f);
BLUE_API const b_string *b_stringstream_str(b_stringstream *f);
BLUE_API const char *b_stringstream_cstr(b_stringstream *f);
BLUE_API void b_stringstream_clear(b_stringstream *f);
BLUE_API void b_stringstream_push_indent(b_stringstream *f, int indent);
BLUE_API void b_stringstream_push_indent_abs(b_stringstream *f, int indent);
BLUE_API void b_stringstream_pop_indent(b_stringstream *f);
BLUE_API void b_stringstream_add(b_stringstream *f, const char *s);
BLUE_API void b_stringstream_addf(b_stringstream *f, const char *format, ...);
BLUE_API void b_stringstream_addvf(b_stringstream *f, const char *format, va_list arg);
BLUE_API void b_stringstream_add_str(b_stringstream *f, const b_string *str);
#endif

View File

@@ -11,7 +11,7 @@
#define B_UUID_STRING_MAX 37
struct b_string;
struct b_strv_builder;
struct b_stringstream;
typedef struct b_uuid b_uuid;
@@ -42,8 +42,8 @@ static inline void b_uuid_release(b_uuid *uuid)
BLUE_API b_status b_uuid_to_string(const b_uuid *uuid, struct b_string *out);
BLUE_API b_status b_uuid_to_cstr(const b_uuid *uuid, char out[B_UUID_STRING_MAX]);
BLUE_API b_status b_uuid_to_strv_builder(
const b_uuid *uuid, struct b_strv_builder *out);
BLUE_API b_status b_uuid_to_stringstream(
const b_uuid *uuid, struct b_stringstream *out);
BLUE_API void b_uuid_get_bytes(
const b_uuid *uuid, unsigned char bytes[B_UUID_NBYTES]);
BLUE_API void b_uuid_get_uuid_bytes(const b_uuid *uuid, b_uuid_bytes *bytes);