aboutsummaryrefslogtreecommitdiff
path: root/stdlib/bools.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-21 21:48:53 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-21 21:48:53 -0400
commit5ee185a4896e43c67b6d299becfa616da78fb9f4 (patch)
tree183ceef2fd21230c89334d7d039255d1c86c5dca /stdlib/bools.c
parentf4aaf7b73481248f6768302be688700a364a1af8 (diff)
Move stdlib into src/
Diffstat (limited to 'stdlib/bools.c')
-rw-r--r--stdlib/bools.c57
1 files changed, 0 insertions, 57 deletions
diff --git a/stdlib/bools.c b/stdlib/bools.c
deleted file mode 100644
index bf820664..00000000
--- a/stdlib/bools.c
+++ /dev/null
@@ -1,57 +0,0 @@
-// Boolean methods/type info
-#include <ctype.h>
-#include <err.h>
-#include <gc.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <sys/param.h>
-
-#include "bools.h"
-#include "optionals.h"
-#include "text.h"
-#include "util.h"
-
-PUREFUNC public Text_t Bool$as_text(const void *b, bool colorize, const TypeInfo_t*)
-{
- if (!b) return Text("Bool");
- if (colorize)
- return *(Bool_t*)b ? Text("\x1b[35myes\x1b[m") : Text("\x1b[35mno\x1b[m");
- else
- return *(Bool_t*)b ? Text("yes") : Text("no");
-}
-
-PUREFUNC public OptionalBool_t Bool$parse(Text_t text)
-{
- if (Text$equal_ignoring_case(text, Text("yes"), NONE_TEXT)
- || Text$equal_ignoring_case(text, Text("on"), NONE_TEXT)
- || Text$equal_ignoring_case(text, Text("true"), NONE_TEXT)
- || Text$equal_ignoring_case(text, Text("1"), NONE_TEXT)) {
- return yes;
- } else if (Text$equal_ignoring_case(text, Text("no"), NONE_TEXT)
- || Text$equal_ignoring_case(text, Text("off"), NONE_TEXT)
- || Text$equal_ignoring_case(text, Text("false"), NONE_TEXT)
- || Text$equal_ignoring_case(text, Text("0"), NONE_TEXT)) {
- return no;
- } else {
- return NONE_BOOL;
- }
-}
-
-static bool Bool$is_none(const void *b, const TypeInfo_t*)
-{
- return *(OptionalBool_t*)b == NONE_BOOL;
-}
-
-static const metamethods_t Bool$metamethods = {
- .as_text=Bool$as_text,
- .is_none=Bool$is_none,
-};
-
-public const TypeInfo_t Bool$info = {
- .size=sizeof(bool),
- .align=__alignof__(bool),
- .metamethods=Bool$metamethods,
-};
-
-// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0