commit b634166def7d811c988325db42e78904f8686793
parent a1a97fcddea3141a42d8281e9968fc5c05ed4d51
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Fri, 12 May 2023 21:51:44 +0200
datetime: fail on invalid format specifier
Invalid layout formats shall fail rather than be silently ignored.
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/datetime/parse.ha b/datetime/parse.ha
@@ -25,6 +25,8 @@ export type parsefail = !rune;
// datetime::parse(&v, "%H:%M:%S.%N", "22:07:08.000000000");
// datetime::parse(&v, "%z %Z %L", "+0100 CET Europe/Amsterdam");
//
+// Parse will return parsefail, if an invalid format specifier is encountered
+// or if given string 's' does not match the layout.
export fn parse(v: *virtual, layout: str, s: str) (void | parsefail) = {
const liter = strings::iter(layout);
const siter = strings::iter(s);
@@ -131,7 +133,7 @@ fn parse_specifier(
case '%' =>
eat_rune(iter, '%')?;
case =>
- void; // Ignore invalid specifier
+ return failure;
};
};