+csv dep for PG'OCaml.
[cocanwiki.git] / scripts / lib / cocanwiki_ext_calendar.ml
index bb80fb8..1fd11ba 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_ext_calendar.ml,v 1.5 2006/07/27 16:46:55 rich Exp $
+ * $Id: cocanwiki_ext_calendar.ml,v 1.6 2006/08/16 15:27:02 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -53,6 +53,8 @@ let rec range a b =
   else
     []
 
+let ascii_isdigit = function '0'..'9' -> true | _ -> false
+
 let extension r dbh hostid url =
   (* Validate a date in the form "yyyy[/mm[/dd]]".  Returns a (yyyy, mm, dd)
    * tuple with missing fields set to 0.  If the string doesn't parse or the
@@ -60,27 +62,27 @@ let extension r dbh hostid url =
    *)
   let valid_date str =
     if String.length str = 4 &&
-      isdigit str.[0] && isdigit str.[1] &&
-      isdigit str.[2] && isdigit str.[3] then (
+      ascii_isdigit str.[0] && ascii_isdigit str.[1] &&
+      ascii_isdigit str.[2] && ascii_isdigit str.[3] then (
        let yyyy = int_of_string (String.sub str 0 4) in
        (yyyy, 0, 0)
       )
     else if String.length str = 7 &&
-      isdigit str.[0] && isdigit str.[1] &&
-      isdigit str.[2] && isdigit str.[3] &&
+      ascii_isdigit str.[0] && ascii_isdigit str.[1] &&
+      ascii_isdigit str.[2] && ascii_isdigit str.[3] &&
       str.[4] = '/' &&
-      isdigit str.[5] && isdigit str.[6] then (
+      ascii_isdigit str.[5] && ascii_isdigit str.[6] then (
        let yyyy = int_of_string (String.sub str 0 4) in
        let mm = int_of_string (String.sub str 5 2) in
        if mm >= 1 && mm <= 12 then (yyyy, mm, 0) else raise Not_found
       )
     else if String.length str = 10 &&
-      isdigit str.[0] && isdigit str.[1] &&
-      isdigit str.[2] && isdigit str.[3] &&
+      ascii_isdigit str.[0] && ascii_isdigit str.[1] &&
+      ascii_isdigit str.[2] && ascii_isdigit str.[3] &&
       str.[4] = '/' &&
-      isdigit str.[5] && isdigit str.[6] &&
+      ascii_isdigit str.[5] && ascii_isdigit str.[6] &&
       str.[7] = '/' &&
-      isdigit str.[8] && isdigit str.[9] then (
+      ascii_isdigit str.[8] && ascii_isdigit str.[9] then (
        let yyyy = int_of_string (String.sub str 0 4) in
        let mm = int_of_string (String.sub str 5 2) in
        let dd = int_of_string (String.sub str 8 2) in