[Pkg-ocaml-maint-commits] r2338 - trunk/projects/ocaml-deblib

Stefano Zacchiroli zack at costa.debian.org
Wed Dec 28 13:56:45 UTC 2005


Author: zack
Date: 2005-12-28 13:56:44 +0000 (Wed, 28 Dec 2005)
New Revision: 2338

Modified:
   trunk/projects/ocaml-deblib/deblib_Version.ml
   trunk/projects/ocaml-deblib/deblib_Version.mli
Log:
added:
- low level access to pieces (digits/non digits) of string versions
- added patching (increase/decrease) of debian version part


Modified: trunk/projects/ocaml-deblib/deblib_Version.ml
===================================================================
--- trunk/projects/ocaml-deblib/deblib_Version.ml	2005-12-28 13:51:16 UTC (rev 2337)
+++ trunk/projects/ocaml-deblib/deblib_Version.ml	2005-12-28 13:56:44 UTC (rev 2338)
@@ -15,6 +15,8 @@
 
 exception Malformed of string
 
+let err_int_expected s = raise (Malformed (sprintf "expecting an int: %s\n" s))
+
 let upstream_regexp = Str.regexp "^[0-9a-zA-Z.+:-]+$";;
 let check_upstream s = Str.string_match upstream_regexp s 0
   
@@ -40,7 +42,7 @@
     let e = 
       let int_s = Str.matched_group 1 s in
       try Int64.of_string int_s
-      with Failure _ -> raise (Malformed (sprintf "expecting an int: %s\n" int_s))
+      with Failure _ -> err_int_expected int_s
     in
     let rest = (Str.matched_group 2 s) in
       parse_debian e rest
@@ -64,10 +66,10 @@
   let chr_cmp c1 c2 = 
     match c1,c2 with
       | ('a'..'z'|'A'..'Z'),('a'..'z'|'A'..'Z') -> compare c1 c2
-      | ('.'|'+'|'-'|':'),('.'|'+'|'-'|':') -> compare c1 c2
+      | ('+'|'-'|'.'|':'),('+'|'-'|'.'|':') -> compare c1 c2
 	  (* letter comes before a symbol *)
-      | ('a'..'z'|'A'..'Z'),('.'|'+'|'-'|':') -> -1
-      | ('.'|'+'|'-'|':'),('a'..'z'|'A'..'Z') -> 1
+      | ('a'..'z'|'A'..'Z'),('+'|'-'|'.'|':') -> -1
+      | ('+'|'-'|'.'|':'),('a'..'z'|'A'..'Z') -> 1
       | _ -> assert false
   in
   let rec helper s1 s2 idx = 
@@ -82,7 +84,7 @@
 	  else helper s1 s2 (idx+1)
   in
     helper str1 str2 0
-	
+
 let rec compare_non_digit s1 s2 = 
   let non1,rest1 = split non_digit_regexp s1 in
   let non2,rest2 = split non_digit_regexp s2 in
@@ -120,3 +122,47 @@
     then up
     else deb
 
+type version_slice = [ `Non_digits of string | `Digits of string ]
+
+let explode_version s =
+  let rec aux_non_digits s =
+    let non, rest = split non_digit_regexp s in
+    (if non <> "" then [ `Non_digits non ] else [])
+    @ (if rest <> "" then aux_digits rest else [])
+  and aux_digits s =
+    let digits, rest = split digit_regexp s in
+    (if digits <> "" then [ `Digits digits ] else [])
+    @ (if rest <> "" then aux_non_digits rest else [])
+  in
+  aux_non_digits s
+
+let implode_version v =
+  String.concat "" (List.map (function `Non_digits s | `Digits s -> s) v)
+
+let patch_fst_debian_digit f t =
+  let rec aux =
+    function
+      | [] ->
+          failwith (sprintf "Can't patch non-digit Debian version %s" t.debian)
+      | `Digits s :: tl -> `Digits (f s) :: tl
+      | hd :: tl -> hd :: aux tl in
+  if t.debian = "" then
+    failwith "Missing Debian version"
+  else
+    { t with debian = implode_version (aux (explode_version t.debian)) }
+
+let increase_digit s =
+  try
+    Int64.to_string (Int64.succ (Int64.of_string s))
+  with Failure _ -> err_int_expected s
+
+let decrease_digit s =
+  let i = try Int64.of_string s with Failure _ -> err_int_expected s in
+  if Int64.compare i Int64.zero = 0 then
+    failwith (sprintf "Can't decrease digit %s below 0" s)
+  else
+    Int64.to_string (Int64.pred i)
+
+let increase_debian t = patch_fst_debian_digit increase_digit t
+let decrease_debian t = patch_fst_debian_digit decrease_digit t
+

Modified: trunk/projects/ocaml-deblib/deblib_Version.mli
===================================================================
--- trunk/projects/ocaml-deblib/deblib_Version.mli	2005-12-28 13:51:16 UTC (rev 2337)
+++ trunk/projects/ocaml-deblib/deblib_Version.mli	2005-12-28 13:56:44 UTC (rev 2338)
@@ -9,8 +9,14 @@
 exception Malformed of string
 
 val create : string -> t
-
 val to_string : t -> string
-
 val compare : t -> t -> int
 
+type version_slice = [ `Non_digits of string | `Digits of string ]
+
+val explode_version: string -> version_slice list
+val implode_version: version_slice list -> string
+
+val increase_debian : t -> t
+val decrease_debian : t -> t
+




More information about the Pkg-ocaml-maint-commits mailing list