2024-10-24 19:24:54 +01:00
|
|
|
#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_object s_base;
|
2025-09-22 10:36:26 +01:00
|
|
|
/* length of string in bytes, not including null-terminator.
|
|
|
|
|
* a multi-byte utf-8 codepoint will be counted as multiple bytes here */
|
2024-10-24 19:24:54 +01:00
|
|
|
unsigned int s_len;
|
2025-09-22 10:36:26 +01:00
|
|
|
/* 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 */
|
2024-10-24 19:24:54 +01:00
|
|
|
unsigned int s_max;
|
|
|
|
|
union {
|
|
|
|
|
char d_inline[STRING_INLINE_CAPACITY + 1];
|
2024-11-17 09:22:39 +00:00
|
|
|
char *d_external;
|
2024-10-24 19:24:54 +01:00
|
|
|
} s_data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|