79 lines
2.8 KiB
C
79 lines
2.8 KiB
C
#ifndef BLUELIB_STRING_H_
|
|
#define BLUELIB_STRING_H_
|
|
|
|
#include <blue/core/status.h>
|
|
#include <blue/object/object.h>
|
|
#include <blue/object/type.h>
|
|
|
|
#define B_STRING(p) ((b_string *)(p))
|
|
|
|
#define B_CSTR(s) (b_string_create_from_cstr(s))
|
|
#define B_RV_CSTR(s) (B_RV(b_string_create_from_cstr(s)))
|
|
|
|
typedef struct b_string b_string;
|
|
|
|
typedef enum b_strlen_flags {
|
|
B_STRLEN_NORMAL = 0,
|
|
B_STRLEN_IGNORE_ESC = 0x01u,
|
|
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);
|
|
|
|
static inline b_string *b_string_retain(b_string *str)
|
|
{
|
|
return B_STRING(b_retain(B_OBJECT(str)));
|
|
}
|
|
static inline void b_string_release(b_string *str)
|
|
{
|
|
b_release(B_OBJECT(str));
|
|
}
|
|
BLUE_API char *b_string_steal(b_string *str);
|
|
BLUE_API b_status b_string_reserve(b_string *str, size_t capacity);
|
|
|
|
BLUE_API void b_string_append_s(b_string *dest, const b_string *src);
|
|
BLUE_API void b_string_append_cstr(b_string *dest, const char *src);
|
|
BLUE_API void b_string_append_cstrf(b_string *dest, const char *format, ...);
|
|
BLUE_API void b_string_prepend_s(b_string *dest, const b_string *src);
|
|
BLUE_API void b_string_prepend_cstr(b_string *dest, const char *src);
|
|
BLUE_API void b_string_prepend_cstrf(b_string *dest, const char *format, ...);
|
|
BLUE_API void b_string_insert_s(b_string *dest, const b_string *src, size_t at);
|
|
BLUE_API void b_string_insert_cstr(b_string *dest, const char *src, size_t at);
|
|
BLUE_API void b_string_insert_cstrn(
|
|
b_string *dest, const char *src, size_t len, size_t at);
|
|
BLUE_API void b_string_insert_cstrf(
|
|
b_string *dest, size_t at, const char *format, ...);
|
|
BLUE_API void b_string_clear(b_string *str);
|
|
|
|
BLUE_API size_t b_string_get_size(const b_string *str, b_strlen_flags flags);
|
|
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);
|
|
|
|
BLUE_API uint64_t b_cstr_hash(const char *s);
|
|
|
|
#endif
|