summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-08-25 19:25:56 -0400
committerAndrew Opalach <andrew@akon.city> 2026-08-25 19:25:56 -0400
commit20f9d23538811dde9ce8aea051408a05e178b6d4 (patch)
treed2afbc45345dad0d6c0a5456c4e6f2bc87d9202f
parentf6d6c613bf6d770a148e30afa4b94fd163e96d6a (diff)
downloadlibalabaster-20f9d23538811dde9ce8aea051408a05e178b6d4.tar.gz
libalabaster-20f9d23538811dde9ce8aea051408a05e178b6d4.tar.bz2
libalabaster-20f9d23538811dde9ce8aea051408a05e178b6d4.zip
str: al_str_null() -> AL_STR_EMPTY
Signed-off-by: Andrew Opalach <andrew@akon.city>
-rw-r--r--include/al/str.h5
-rw-r--r--tests/str.c13
2 files changed, 10 insertions, 8 deletions
diff --git a/include/al/str.h b/include/al/str.h
index a572dec..e993cce 100644
--- a/include/al/str.h
+++ b/include/al/str.h
@@ -11,7 +11,7 @@ typedef struct {
#define AL_STR_NO_POS ((u32)-1)
-#define al_str_null() ((str){ 0, 0, NULL })
+#define AL_STR_EMPTY ((str){ 0, 0, NULL })
#define al_str_at(s, index) (s)->data[index]
#define al_str_atr(s, index) (s)->data[(s)->length - (index)]
@@ -43,7 +43,7 @@ static inline u32 al_str_reserve(str *s, u32 size)
static inline void al_str_sized(str *s, u32 size)
{
- *s = al_str_null();
+ *s = AL_STR_EMPTY;
s->alloc = al_str_reserve(s, size);
}
@@ -88,6 +88,7 @@ static inline char *al_str_to_c_str(str *s)
static inline void al_str_cat(str *s, str *c)
{
+ al_assert(c->data && c->length > 0);
s->alloc = al_str_reserve(s, s->length + c->length);
al_memcpy(s->data + s->length, c->data, c->length);
s->length += c->length;
diff --git a/tests/str.c b/tests/str.c
index 933b1f9..2b02297 100644
--- a/tests/str.c
+++ b/tests/str.c
@@ -47,10 +47,11 @@ static bool str_test_cat(void)
str result = al_str_c("hygshiylitf");
- str string0;
- al_str_from(&string0, "hyg");
+ str string0 = AL_STR_EMPTY;
+ al_str_cat(&string0, &al_str_c("hyg"));
AL_TEST_EQ(string0.length, 3, u32);
+ AL_TEST_GTE(string0.alloc, 3, u32);
al_str_cat(&string0, &al_str_c("shiylitf"));
@@ -167,7 +168,7 @@ static bool str_test_get_line(void)
for (u32 i = 0; i < ARRAY_SIZE(strings); i++) {
u32 counter = 0;
- str line = al_str_null();
+ str line = AL_STR_EMPTY;
for (; al_str_get_line(&strings[i], '\n', &line); ) {
AL_TEST_LT(counter, sizes[i], u32);
AL_TEST_TRUE(al_str_eq(&line, &arrays[i][counter++]));
@@ -176,7 +177,7 @@ static bool str_test_get_line(void)
AL_TEST_EQ(counter, sizes[i], u32);
counter = 0;
- line = al_str_null();
+ line = AL_STR_EMPTY;
// One empty line.
for (; al_str_get_line(&al_str_c("\n"), '\n', &line); ) {
AL_TEST_LT(counter, 1, u32);
@@ -185,7 +186,7 @@ static bool str_test_get_line(void)
}
// No lines.
- line = al_str_null();
+ line = AL_STR_EMPTY;
AL_TEST_FALSE(al_str_get_line(&al_str_c(""), '\n', &line));
}
@@ -337,7 +338,7 @@ static bool str_test_limits(void)
{
AL_TEST_START("str_limits");
- str s = al_str_null();
+ str s = AL_STR_EMPTY;
for (u32 i = 0; i < MAX_ALLOC_32 - 1; i++) {
al_str_cat(&s, &al_str_c("y"));