summaryrefslogtreecommitdiff
path: root/src/c/urweb.c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-09-07 11:41:04 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-09-07 11:41:04 -0400
commit9ae8932c978ab9c12f683745b47b3e0898581635 (patch)
tree92fd1f76d01cbe023599cb2d43215f82fb552960 /src/c/urweb.c
parent5cf1d4d086475575a31f57413c57c22bd6fda378 (diff)
Parsing strings for floats and bools
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r--src/c/urweb.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index dce33bf1..bf697340 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -769,3 +769,27 @@ lw_Basis_int *lw_Basis_stringToInt(lw_context ctx, lw_Basis_string s) {
} else
return NULL;
}
+
+lw_Basis_float *lw_Basis_stringToFloat(lw_context ctx, lw_Basis_string s) {
+ char *endptr;
+ lw_Basis_float n = strtod(s, &endptr);
+
+ if (*s != '\0' && *endptr == '\0') {
+ lw_Basis_float *r = lw_malloc(ctx, sizeof(lw_Basis_float));
+ *r = n;
+ return r;
+ } else
+ return NULL;
+}
+
+lw_Basis_bool *lw_Basis_stringToBool(lw_context ctx, lw_Basis_string s) {
+ static lw_Basis_bool true = lw_Basis_True;
+ static lw_Basis_bool false = lw_Basis_False;
+
+ if (!strcasecmp (s, "True"))
+ return &true;
+ else if (!strcasecmp (s, "False"))
+ return &false;
+ else
+ return NULL;
+}