commit f4e6b6ac950ec5055bf37b883ef36faf513633a2
parent a90f2323ba1e212d50bfb6a3d33fb332cf168f1f
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Sun, 9 Oct 2022 20:51:12 +0200
strconv: add strerror
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/strconv/types.ha b/strconv/types.ha
@@ -11,6 +11,9 @@ export type invalid = !size;
// requested data type.
export type overflow = !void;
+// Any error which may be returned from a strconv function.
+export type error = (invalid | overflow);
+
// The valid numeric bases for numeric conversions.
export type base = enum uint {
// Base 2, binary
@@ -26,3 +29,13 @@ export type base = enum uint {
// Base 16, lowercase hexadecimal
HEX_LOWER = 17,
};
+
+// Converts an strconv [[error]] into a user-friendly string.
+export fn strerror(err: error) str = {
+ match (err) {
+ case invalid =>
+ return "Input string is not an integer";
+ case overflow =>
+ return "Input number overflows integer type";
+ };
+};