ds: string: convert to new object system

This commit is contained in:
2025-10-19 11:02:36 +01:00
parent 3ee9de74f0
commit 3eebdddc21
3 changed files with 514 additions and 381 deletions

View File

@@ -1,16 +1,23 @@
#ifndef BLUELIB_STRING_H_ #ifndef BLUE_DS_STRING_H_
#define BLUELIB_STRING_H_ #define BLUE_DS_STRING_H_
#include <blue/core/encoding.h> #include <blue/core/encoding.h>
#include <blue/core/iterator.h> #include <blue/core/iterator.h>
#include <blue/core/macros.h>
#include <blue/core/status.h> #include <blue/core/status.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
#include <ctype.h> #include <ctype.h>
struct b_stream; B_DECLS_BEGIN;
#define B_STRING(p) ((b_string *)(p)) struct b_stream;
struct b_string_p;
#define B_TYPE_STRING (b_string_get_type())
B_DECLARE_TYPE(b_string);
B_TYPE_CLASS_DECLARATION_BEGIN(b_string)
B_TYPE_CLASS_DECLARATION_END(b_string)
#define B_CSTR(s) (b_string_create_from_cstr(s)) #define B_CSTR(s) (b_string_create_from_cstr(s))
#define B_RV_CSTR(s) (B_RV(b_string_create_from_cstr(s))) #define B_RV_CSTR(s) (B_RV(b_string_create_from_cstr(s)))
@@ -19,12 +26,12 @@ struct b_stream;
for (int z__b_unique_name() = b_string_iterator_begin(str, it); \ for (int z__b_unique_name() = b_string_iterator_begin(str, it); \
b_string_iterator_is_valid(it); b_string_iterator_next(it)) b_string_iterator_is_valid(it); b_string_iterator_next(it))
typedef struct b_string b_string;
typedef struct b_string_iterator { typedef struct b_string_iterator {
b_iterator _base; b_iterator _base;
int _m, _f; int _m, _f;
b_string *_s, *_tmp; b_string *_tmp;
struct b_string_p *_s_p, *_tmp_p;
const char **_d; const char **_d;
size_t _nd, _ds; size_t _nd, _ds;
@@ -50,20 +57,14 @@ typedef enum b_string_tokenise_flags {
B_STRING_TOK_F_INCLUDE_EMPTY_TOKENS = 0x01u, B_STRING_TOK_F_INCLUDE_EMPTY_TOKENS = 0x01u,
} b_string_tokenise_flags; } b_string_tokenise_flags;
BLUE_API b_string *b_string_create(void); BLUE_API b_type b_string_get_type(void);
B_TYPE_DEFAULT_CONSTRUCTOR(b_string, B_TYPE_STRING);
BLUE_API b_string *b_string_create_from_cstr(const char *s); BLUE_API b_string *b_string_create_from_cstr(const char *s);
BLUE_API b_string *b_string_create_from_wstr(const b_wchar *s); BLUE_API b_string *b_string_create_from_wstr(const b_wchar *s);
BLUE_API b_string *b_string_create_from_c(char c, size_t count); BLUE_API b_string *b_string_create_from_c(char c, size_t count);
BLUE_API b_string *b_string_duplicate(const b_string *str); BLUE_API b_string *b_string_duplicate(const b_string *str);
static inline b_string *b_string_retain(b_string *str)
{
return B_STRING(b_retain(B_DSREF(str)));
}
static inline void b_string_release(b_string *str)
{
b_release(B_DSREF(str));
}
BLUE_API char *b_string_steal(b_string *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 b_status b_string_reserve(b_string *str, size_t capacity);
BLUE_API b_status b_string_replace( BLUE_API b_status b_string_replace(
@@ -138,4 +139,6 @@ BLUE_API size_t b_wstrlen(const b_wchar *s);
BLUE_API uint64_t b_string_hash(const b_string *s); BLUE_API uint64_t b_string_hash(const b_string *s);
B_DECLS_END;
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +0,0 @@
#ifndef _BLUELIB_STRING_H_
#define _BLUELIB_STRING_H_
#include "object.h"
/* maximum length of string that can be stored inline, not including null-terminator */
#define STRING_INLINE_CAPACITY 15
struct b_string {
struct b_dsref s_base;
/* length of string in bytes, not including null-terminator.
* a multi-byte utf-8 codepoint will be counted as multiple bytes here */
unsigned int s_len;
/* length of string in codepoints, not including null-terminator.
* a multi-byte utf-8 codepoint will be counted as one codepoint here */
unsigned int s_codepoints;
/* maximum length of string storable in the currently-allocated buffer
* in bytes, not including null terminator */
unsigned int s_max;
union {
char d_inline[STRING_INLINE_CAPACITY + 1];
char *d_external;
} s_data;
};
#endif