diff src/c/lacweb.c @ 186:88d46972de53

bool in Basis
author Adam Chlipala <adamc@hcoop.net>
date Sun, 03 Aug 2008 18:53:20 -0400
parents c0ea24dcb86f
children 20bf7487c370
line wrap: on
line diff
--- a/src/c/lacweb.c	Sun Aug 03 17:57:47 2008 -0400
+++ b/src/c/lacweb.c	Sun Aug 03 18:53:20 2008 -0400
@@ -338,6 +338,13 @@
   return r;
 }
 
+char *lw_Basis_urlifyBool(lw_context ctx, lw_Basis_bool b) {
+  if (b->tag == lw_Basis_False)
+    return "0";
+  else
+    return "1";
+}
+
 static void lw_Basis_urlifyInt_w_unsafe(lw_context ctx, lw_Basis_int n) {
   int len;
 
@@ -375,6 +382,13 @@
   }
 }
 
+void lw_Basis_urlifyBool_w(lw_context ctx, lw_Basis_bool b) {
+  if (b->tag == lw_Basis_False)
+    lw_writec(ctx, '0');
+  else
+    lw_writec(ctx, '1');
+}
+
 
 static char *lw_unurlify_advance(char *s) {
   char *new_s = strchr(s, '/');
@@ -387,7 +401,7 @@
   return new_s;
 }
 
-lw_Basis_int lw_unurlifyInt(char **s) {
+lw_Basis_int lw_Basis_unurlifyInt(lw_context ctx, char **s) {
   char *new_s = lw_unurlify_advance(*s);
   int r;
 
@@ -396,7 +410,7 @@
   return r;
 }
 
-lw_Basis_float lw_unurlifyFloat(char **s) {
+lw_Basis_float lw_Basis_unurlifyFloat(lw_context ctx, char **s) {
   char *new_s = lw_unurlify_advance(*s);
   int r;
 
@@ -434,7 +448,23 @@
   return s1;
 }
 
-lw_Basis_string lw_unurlifyString(lw_context ctx, char **s) {
+static struct lw_Basis_bool lw_False = { lw_Basis_False },
+  lw_True = { lw_Basis_True };
+
+lw_Basis_bool lw_Basis_unurlifyBool(lw_context ctx, char **s) {
+  char *new_s = lw_unurlify_advance(*s);
+  lw_Basis_bool r;
+  
+  if (*s[0] == 0 || !strcmp(*s, "0") || !strcmp(*s, "off"))
+    r = &lw_False;
+  else
+    r = &lw_True;
+
+  *s = new_s;
+  return r;
+}
+
+lw_Basis_string lw_Basis_unurlifyString(lw_context ctx, char **s) {
   char *new_s = lw_unurlify_advance(*s);
   char *r, *s1, *s2;
   int len, n;