summaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-09-07 12:19:15 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-09-07 12:19:15 -0400
commit5336dbf5369f77fba0f498a03523faebeed9c5b2 (patch)
treefddd00c363f5625d7d26f043dc903a4d01cf297f /src/c
parent1f893091967ed6a9bd8469a62ddf4017e87d563d (diff)
Error-parsing floats and bools
Diffstat (limited to 'src/c')
-rw-r--r--src/c/urweb.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 1286ca5e..47b45367 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -799,3 +799,22 @@ lw_Basis_int lw_Basis_stringToInt_error(lw_context ctx, lw_Basis_string s) {
else
lw_error(ctx, FATAL, "Can't parse int: %s", s);
}
+
+lw_Basis_float lw_Basis_stringToFloat_error(lw_context ctx, lw_Basis_string s) {
+ char *endptr;
+ lw_Basis_float n = strtod(s, &endptr);
+
+ if (*s != '\0' && *endptr == '\0')
+ return n;
+ else
+ lw_error(ctx, FATAL, "Can't parse float: %s", s);
+}
+
+lw_Basis_bool lw_Basis_stringToBool_error(lw_context ctx, lw_Basis_string s) {
+ if (!strcasecmp (s, "True"))
+ return lw_Basis_True;
+ else if (!strcasecmp (s, "False"))
+ return lw_Basis_False;
+ else
+ lw_error(ctx, FATAL, "Can't parse bool: %s", s);
+}