aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/c_strings.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-23 19:28:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-23 19:28:08 -0400
commitfcda36561d668f43bac91ea31cd55cbbd605d330 (patch)
treeeb74c0b17df584af0fd8154422ad924e04c96cc2 /src/stdlib/c_strings.c
parent414b0c7472c87c5a013029aefef49e2dbc41e700 (diff)
Autoformat everything with clang-format
Diffstat (limited to 'src/stdlib/c_strings.c')
-rw-r--r--src/stdlib/c_strings.c76
1 files changed, 35 insertions, 41 deletions
diff --git a/src/stdlib/c_strings.c b/src/stdlib/c_strings.c
index c2b8efbe..b965f04b 100644
--- a/src/stdlib/c_strings.c
+++ b/src/stdlib/c_strings.c
@@ -12,46 +12,40 @@
#include "text.h"
#include "util.h"
-public Text_t CString$as_text(const void *c_string, bool colorize, const TypeInfo_t *info)
-{
+public
+Text_t CString$as_text(const void *c_string, bool colorize, const TypeInfo_t *info) {
(void)info;
if (!c_string) return Text("CString");
- Text_t text = Text$from_str(*(const char**)c_string);
- return Text$concat(colorize ? Text("\x1b[34mCString\x1b[m(") : Text("CString("), Text$quoted(text, colorize, Text("\"")), Text(")"));
+ Text_t text = Text$from_str(*(const char **)c_string);
+ return Text$concat(colorize ? Text("\x1b[34mCString\x1b[m(") : Text("CString("),
+ Text$quoted(text, colorize, Text("\"")), Text(")"));
}
-PUREFUNC public int32_t CString$compare(const void *x, const void *y, const TypeInfo_t *info)
-{
+PUREFUNC public int32_t CString$compare(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
- if (x == y)
- return 0;
+ if (x == y) return 0;
- if (!*(const char**)x != !*(const char**)y)
- return (!*(const char**)y) - (!*(const char**)x);
+ if (!*(const char **)x != !*(const char **)y) return (!*(const char **)y) - (!*(const char **)x);
- return strcmp(*(const char**)x, *(const char**)y);
+ return strcmp(*(const char **)x, *(const char **)y);
}
-PUREFUNC public bool CString$equal(const void *x, const void *y, const TypeInfo_t *type)
-{
+PUREFUNC public bool CString$equal(const void *x, const void *y, const TypeInfo_t *type) {
return CString$compare(x, y, type) == 0;
}
-PUREFUNC public uint64_t CString$hash(const void *c_str, const TypeInfo_t *info)
-{
+PUREFUNC public uint64_t CString$hash(const void *c_str, const TypeInfo_t *info) {
(void)info;
- if (!*(const char**)c_str) return 0;
- return siphash24(*(void**)c_str, strlen(*(const char**)c_str));
+ if (!*(const char **)c_str) return 0;
+ return siphash24(*(void **)c_str, strlen(*(const char **)c_str));
}
-PUREFUNC public bool CString$is_none(const void *c_str, const TypeInfo_t *info)
-{
+PUREFUNC public bool CString$is_none(const void *c_str, const TypeInfo_t *info) {
(void)info;
- return *(const char**)c_str == NULL;
+ return *(const char **)c_str == NULL;
}
-static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
-{
+static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) {
(void)info;
const char *str = *(const char **)obj;
int64_t len = (int64_t)strlen(str);
@@ -59,30 +53,30 @@ static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, con
fwrite(str, sizeof(char), (size_t)len, out);
}
-static void CString$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info)
-{
+static void CString$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info) {
(void)info;
int64_t len = -1;
Int64$deserialize(in, &len, pointers, &Int64$info);
- char *str = GC_MALLOC_ATOMIC((size_t)len+1);
- if (fread(str, sizeof(char), (size_t)len, in) != (size_t)len)
- fail("Not enough data in stream to deserialize");
- str[len+1] = '\0';
- *(const char**)out = str;
+ char *str = GC_MALLOC_ATOMIC((size_t)len + 1);
+ if (fread(str, sizeof(char), (size_t)len, in) != (size_t)len) fail("Not enough data in stream to deserialize");
+ str[len + 1] = '\0';
+ *(const char **)out = str;
}
-public const TypeInfo_t CString$info = {
- .size=sizeof(const char*),
- .align=__alignof__(const char*),
- .metamethods={
- .hash=CString$hash,
- .compare=CString$compare,
- .equal=CString$equal,
- .as_text=CString$as_text,
- .is_none=CString$is_none,
- .serialize=CString$serialize,
- .deserialize=CString$deserialize,
- },
+public
+const TypeInfo_t CString$info = {
+ .size = sizeof(const char *),
+ .align = __alignof__(const char *),
+ .metamethods =
+ {
+ .hash = CString$hash,
+ .compare = CString$compare,
+ .equal = CString$equal,
+ .as_text = CString$as_text,
+ .is_none = CString$is_none,
+ .serialize = CString$serialize,
+ .deserialize = CString$deserialize,
+ },
};
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0