aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/bytes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib/bytes.c')
-rw-r--r--src/stdlib/bytes.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/stdlib/bytes.c b/src/stdlib/bytes.c
index 48c8b93b..130a645f 100644
--- a/src/stdlib/bytes.c
+++ b/src/stdlib/bytes.c
@@ -3,6 +3,7 @@
#include <stdint.h>
#include "bytes.h"
+#include "integers.h"
#include "stdlib.h"
#include "text.h"
#include "util.h"
@@ -29,6 +30,18 @@ public CONSTFUNC bool Byte$is_between(const Byte_t x, const Byte_t low, const By
return low <= x && x <= high;
}
+public OptionalByte_t Byte$parse(Text_t text, Text_t *remainder)
+{
+ OptionalInt_t full_int = Int$parse(text, remainder);
+ if (full_int.small != 0L
+ && Int$compare_value(full_int, I(0)) >= 0
+ && Int$compare_value(full_int, I(255)) <= 0) {
+ return (OptionalByte_t){.value=Byte$from_int(full_int, true)};
+ } else {
+ return NONE_BYTE;
+ }
+}
+
public Text_t Byte$hex(Byte_t byte, bool uppercase, bool prefix) {
struct Text_s text = {.tag=TEXT_ASCII};
text.ascii = GC_MALLOC_ATOMIC(8);