diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-16 17:21:01 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-16 17:21:01 -0400 |
| commit | c72b0406a32ffc3f04324f7b6c321486762fca41 (patch) | |
| tree | 244e51c858890ea2ffb8c74a2c33c81b79de376e /src/stdlib/bytes.c | |
| parent | 849fd423a759edf1b58b548a6148c177a6f8cd71 (diff) | |
Improved parsing and prefix/suffix matching using a `remainder`
parameter
Diffstat (limited to 'src/stdlib/bytes.c')
| -rw-r--r-- | src/stdlib/bytes.c | 13 |
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); |
