cli: add safe UTF-8 and supplied-buffer hex/base64 std modules

This commit is contained in:
dev committed 2026-10-06 17:06:39 +03:00
1 parent 6397a317e2
commit 3bb11e03b2
42 files changed
+2807 -14

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
module demo.text
import std.bytes;
import std.encoding.hex;
import std.encoding.base64;
import std.utf8;
fn main() -> u32
effects []
{
var utf8: [u8; 3] = zero;
match std.encoding.hex.decode(mut utf8, b"E282AC") {
std.encoding.hex.DecodeResult::ok(count) => { assert(count == 3); }
std.encoding.hex.DecodeResult::invalid_input => { return 0; }
std.encoding.hex.DecodeResult::short_output => { return 0; }
}
match std.utf8.validate(ref utf8) {
std.utf8.ValidateResult::ok => {}
std.utf8.ValidateResult::invalid_input(offset) => { return 0; }
}
var encoded: [u8; 4] = zero;
match std.encoding.base64.encode(mut encoded, ref utf8) {
std.encoding.base64.EncodeResult::ok(count) => { assert(count == 4); }
std.encoding.base64.EncodeResult::short_output => { return 0; }
}
assert(std.bytes.equal(ref encoded, b"4oKs"));
match std.utf8.next(ref utf8) {
std.utf8.NextResult::ok(scalar, count) => { assert(count == 3); return scalar; }
std.utf8.NextResult::end => { return 0; }
std.utf8.NextResult::invalid_input => { return 0; }
}
}