mldonkey-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Mldonkey-commits] mldonkey distribChangeLog src/daemon/common/com...


From: mldonkey-commits
Subject: [Mldonkey-commits] mldonkey distribChangeLog src/daemon/common/com...
Date: Mon, 12 Jun 2006 10:02:59 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Changes by:     spiralvoice <spiralvoice>       06/06/12 10:02:59

Modified files:
        distrib        : ChangeLog 
        src/daemon/common: commonSwarming.ml 
        src/gtk/gui    : gui_downloads.ml gui_friends.ml 
        src/gtk/newgui : gui_downloads.ml gui_types.ml 
        src/gtk2/gui   : guiMisc.ml 
        src/utils/cdk  : array2.ml string2.ml string2.mli 

Log message:
        patch #5174

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/distrib/ChangeLog?cvsroot=mldonkey&r1=1.883&r2=1.884
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonSwarming.ml?cvsroot=mldonkey&r1=1.42&r2=1.43
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/gtk/gui/gui_downloads.ml?cvsroot=mldonkey&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/gtk/gui/gui_friends.ml?cvsroot=mldonkey&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/gtk/newgui/gui_downloads.ml?cvsroot=mldonkey&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/gtk/newgui/gui_types.ml?cvsroot=mldonkey&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/gtk2/gui/guiMisc.ml?cvsroot=mldonkey&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/utils/cdk/array2.ml?cvsroot=mldonkey&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/utils/cdk/string2.ml?cvsroot=mldonkey&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/utils/cdk/string2.mli?cvsroot=mldonkey&r1=1.8&r2=1.9

Patches:
Index: distrib/ChangeLog
===================================================================
RCS file: /sources/mldonkey/mldonkey/distrib/ChangeLog,v
retrieving revision 1.883
retrieving revision 1.884
diff -u -b -r1.883 -r1.884
--- distrib/ChangeLog   12 Jun 2006 10:01:27 -0000      1.883
+++ distrib/ChangeLog   12 Jun 2006 10:02:58 -0000      1.884
@@ -15,6 +15,8 @@
 =========
 
 2006/06/12
+5174: Abstract verification bitmaps:
+      compile fixes for GTK1 GUIs, move generic code to CDK (pango)
 5173: Swarmer: Small fix for merged downloads (WIP7b') (pango)
 
 2006/06/11

Index: src/daemon/common/commonSwarming.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonSwarming.ml,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- src/daemon/common/commonSwarming.ml 12 Jun 2006 10:01:27 -0000      1.42
+++ src/daemon/common/commonSwarming.ml 12 Jun 2006 10:02:58 -0000      1.43
@@ -332,37 +332,6 @@
 
 let swarmer_counter = ref 0
 
-let string_init n f =
-  let s = String.create n in
-  let rec aux i =
-    if i < n then begin
-      s.[i] <- f i;
-      aux (i+1)
-    end in 
-  aux 0;
-  s
-
-let string_iter f s =
-  let l = String.length s in
-  let rec aux i =
-    if i < l then begin
-      f i s.[i];
-      aux (i+1)
-    end in 
-  aux 0
-
-let string_existsi p s =
-  let l = String.length s in
-  let rec aux i =
-    i < l && (p i s.[i] || aux (i+1)) in
-  aux 0
-
-let string_for_all p s =
-  let l = String.length s in
-  let rec aux i =
-    i >= l || p s.[i] && aux (i+1) in
-  aux 0
-
 (** sets [t.t_last_seen] of the verified blocks to current time, and 
     associated file's [t.t_s.s_file] last seen value to the oldest of the
     remaining last seen values *)
@@ -743,14 +712,9 @@
   let nblocks = List.length blocks in
 (*  lprintf "%d blocks to generate\n" nblocks; *)
 
-  let array_exist p a =
-    let l = Array.length a in
-    let rec aux i = (i < l) && (p a.(i) || aux (i+1)) in
-    aux 0 in
-
-  if array_exist ((<>) 0) s.s_availability then
+  if Array2.exists ((<>) 0) s.s_availability then
     lprintf_nl "WARNING: splitting swarmer discarded availability counters";
-  if array_exist ((<>) 0) s.s_nuploading then
+  if Array2.exists ((<>) 0) s.s_nuploading then
     lprintf_nl "WARNING: splitting a swarmer beging uploaded to";
 
   s.s_blocks <- Array.create nblocks EmptyBlock;
@@ -1976,24 +1940,6 @@
   choice_availability = 0
 }
 
-(* based on Array.fold_left code *)
-let array_fold_lefti f x a =
-  let r = ref x in
-  for i = 0 to Array.length a - 1 do
-    r := f !r i (Array.unsafe_get a i)
-  done;
-  !r
-
-let subarray_fold_lefti f x a firstidx lastidx =
-  let len = Array.length a in
-  assert(firstidx >= 0 && firstidx < len);
-  assert(lastidx >= 0 && lastidx < len);
-  let r = ref x in
-  for i = firstidx to lastidx do
-    r := f !r i (Array.unsafe_get a i)
-  done;
-  !r
-
 let select_block up =
   let t = up.up_t in
   let s = t.t_s in
@@ -2225,7 +2171,7 @@
          | _ -> assert false in
 
        let best_choices, specimen = 
-         subarray_fold_lefti (fun ((best_choices, specimen) as acc) n b ->
+         Array2.subarray_fold_lefti (fun ((best_choices, specimen) as acc) n b 
->
          (* priority bitmap <> 0 here ? *)
          if not (should_download_block s b) then acc else
            let this_choice = evaluate_choice n b in
@@ -2272,7 +2218,7 @@
                true in
          if probably_buggy then begin
            lprintf_nl "Probably buggy choice:";
-           subarray_fold_lefti (fun () n b ->
+           Array2.subarray_fold_lefti (fun () n b ->
              if should_download_block s b then
                let this_choice = evaluate_choice n b in
                if List.mem n best_choices then lprintf "** "
@@ -2729,7 +2675,7 @@
            (last_interval_begin, interval_end) :: other_intervals in
 
   List.rev (
-    array_fold_lefti (fun acc i b -> 
+    Array2.fold_lefti (fun acc i b -> 
       match s.s_blocks.(i) with
       | EmptyBlock -> acc
       | CompleteBlock | VerifiedBlock ->
@@ -2834,7 +2780,7 @@
 
 let chunks_availability t =
   let s = t.t_s in
-  string_init (partition_size t) (fun i ->
+  String2.init (partition_size t) (fun i ->
     char_of_int (
       let v = List2.min
         (List.map (fun i -> s.s_availability.(i)) t.t_blocks_of_chunk.(i)) in

Index: src/gtk/gui/gui_downloads.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/gtk/gui/gui_downloads.ml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- src/gtk/gui/gui_downloads.ml        14 Dec 2005 21:22:07 -0000      1.9
+++ src/gtk/gui/gui_downloads.ml        12 Jun 2006 10:02:58 -0000      1.10
@@ -115,23 +115,21 @@
   with _ -> 0.0
 
 let file_availability f =
+  match f.file_chunks with
+  | None -> "---"
+  | Some chunks ->
   match f.file_availability with
     (_,avail) :: _ ->
       let rec loop i p n =
-        if i < 0
-        then
-          if n = 0.0
-          then "---"
-          else Printf.sprintf "%5.1f" (p /. n *. 100.0)
+            if i < 0 then
+              if n = 0 then "---"
+              else Printf.sprintf "%5.1f" ((float p) /. (float n) *. 100.0)
         else
-          if CommonGlobals.partial_chunk f.file_chunks.[i]
-          then
-           if avail.[i] <> (char_of_int 0)
-           then loop (i - 1) (p +. 1.0) (n +. 1.0)
-           else loop (i - 1) p (n +. 1.0)
-         else loop (i - 1) p n
+             loop (i - 1)
+               (if CommonGlobals.partial_chunk (VerificationBitmap.get chunks 
i) then p + 1 else p)
+               (if avail.[i] <> (char_of_int 0) then n + 1 else n)
       in
-      loop ((String.length avail) - 1) 0.0 0.0
+         loop ((String.length avail) - 1) 0 0
   | _ -> "---"
 
 let string_availability f =
@@ -485,10 +483,13 @@
 
   
 let draw_chunks (drawing : unit GDraw.drawable) file =
+  match file.file_chunks with
+  | None -> ()
+  | Some chunks ->
   let wx, wy = drawing#size in
   drawing#set_foreground colorWhite;
   drawing#rectangle ~filled: true ~x:0 ~y:0 ~width:wx ~height:wy ();
-  let nchunks = String.length file.file_chunks in
+      let nchunks = VerificationBitmap.length chunks in
   let dx = min !!O.chunk_width (wx / nchunks) in
   
   if wx > nchunks*dx && dx > 0 then
@@ -498,11 +499,11 @@
     let dx2 = if dx <= 2 then dx else dx - 1 in
     for i = 0 to nchunks - 1 do
       drawing#set_foreground (
-        match file.file_chunks.[i] with
-        | '0' -> colorRed
-        | '1' -> colorBlue
-        | '2' -> colorBlack
-        | _ -> colorGreen);
+            match VerificationBitmap.get chunks i with
+            | VerificationBitmap.State_missing -> colorRed
+            | VerificationBitmap.State_partial -> colorBlue
+            | VerificationBitmap.State_complete -> colorBlack
+            | VerificationBitmap.State_verified -> colorGreen);
       drawing#rectangle ~filled: true
       ~x:(offset + i*dx) ~y: 0 
         ~width: dx2 ~height:wy ()
@@ -513,21 +514,19 @@
   let chunk n =
     let p = n * group in
     let get i = 
-      let v = 
-        if i < nchunks then file.file_chunks.[i] else '2'
-      in
-      v
+            if i < nchunks then VerificationBitmap.get chunks i
+           else VerificationBitmap.State_complete
     in
-    let current = String.make 1 (get p) in
+         let current = get p in
     for i = p+1 to p+group-1 do
-      current.[0] <- (
+           current <- (
         match get i, current with
-          '0',"0" -> '0'
-        | '1', _ -> '1'
-        | ('2' | '3'), ("2"|"3") -> '2'
+             | VB.State_missing, '0' -> '0'
+              | VB.State_partial, _ -> '1'
+              | (VB.State_complete | VB.State_verified), ('2'|'3') -> '2'
         | _ -> '1')
     done;
-    current.[0]
+         String.make 1 (char_of_int current)
   in
   let dx = 1 in
   let nchunks = nchunks / group in  
@@ -538,11 +537,11 @@
   for i = 0 to nchunks - 1 do
     let chunk = chunk i in
     drawing#set_foreground (
-        match file.file_chunks.[i] with
-        | '0' -> colorRed
-        | '1' -> colorBlue
-        | '2' -> colorBlack
-        | _ -> colorGreen);
+            match VerificationBitmap.get chunks i with
+            | VerificationBitmap.State_missing -> colorRed
+            | VerificationBitmap.State_partial -> colorBlue
+            | VerificationBitmap.State_complete -> colorBlack
+            | VerificationBitmap.State_verified -> colorGreen);
     drawing#rectangle ~filled: true
     ~x:(offset + i*dx) ~y: 0 
       ~width: dx2 ~height:wy ()

Index: src/gtk/gui/gui_friends.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/gtk/gui/gui_friends.ml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- src/gtk/gui/gui_friends.ml  10 Feb 2004 23:25:08 -0000      1.5
+++ src/gtk/gui/gui_friends.ml  12 Jun 2006 10:02:58 -0000      1.6
@@ -30,6 +30,7 @@
 module O = Gui_options
 module Mi = Gui_misc
 module G = Gui_global
+module VB = VerificationBitmap
 
 let (!!) = Options.(!!)
 
@@ -496,16 +497,25 @@
                       avail_label#misc#show ();
                       
                       let wx, wy = d#size in
-                      let nchunks = String.length file.file_chunks in
+                     (match file.file_chunks with
+                     | None -> ()
+                     | Some chunks ->
+                         let nchunks = VB.length chunks in
                       let dx = if wx < nchunks then 1 else min !!O.chunk_width 
(wx / nchunks) in
                       let dx2 = if dx <= 2 then dx else dx - 1 in
                       for j = 0 to nchunks - 1 do
-                        if avail.[j] >= '1' then
-                          d#set_foreground (if file.file_chunks.[j] >= '2' 
then colorDGreen else colorGreen)
-                        else
-                          d#set_foreground (if file.file_chunks.[j] >= '2' 
then colorDRed else colorRed);
+                           d#set_foreground
+                              (match avail.[j] >= '1', VB.get chunks j with
+                             | true, (VB.State_complete | VB.State_verified) ->
+                                 colorDGreen
+                             | true, (VB.State_missing | VB.State_partial) ->
+                                 colorGreen
+                             | false, (VB.State_complete | VB.State_verified) 
->
+                                 colorDRed
+                             | false, (VB.State_missing | VB.State_partial) ->
+                                 colorRed);
                         d#rectangle ~filled: true ~x:(j*dx) ~y: 0 ~width: dx2 
~height:wy ();
-                      done;
+                         done);
                       
                       false));
                 

Index: src/gtk/newgui/gui_downloads.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/gtk/newgui/gui_downloads.ml,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- src/gtk/newgui/gui_downloads.ml     14 Dec 2005 21:22:07 -0000      1.15
+++ src/gtk/newgui/gui_downloads.ml     12 Jun 2006 10:02:58 -0000      1.16
@@ -39,6 +39,7 @@
 module P = Gpattern
 module O = Gui_options
 module G = Gui_global
+module VB = VerificationBitmap
 
 let use_interested_in_sources = ref false
 let interested_in_sources = ref false
@@ -227,23 +228,15 @@
       
       if !!Gui_options.use_relative_availability
       then
-        let rec loop i =
-          if i < 0
-          then false
+       match f.data.gfile_chunks with
+       | None -> false
+       | Some chunks ->
+           String2.existsi (fun i a ->
+             CommonGlobals.partial_chunk (VB.get chunks i) &&
+               a <> (char_of_int 0)
+           ) avail
           else
-          if CommonGlobals.partial_chunk f.data.gfile_chunks.[i] &&
-            avail.[i] <> (char_of_int 0)
-          then true
-          else loop (i - 1)
-        in
-        loop ((String.length avail) - 1)
-      else
-      let b = ref false in
-      let len = String.length avail in
-      for i = 0 to len - 1 do
-        b := !b or int_of_char avail.[i] <> 0
-      done;
-      !b
+       String2.exists ((<>) (char_of_int 0)) avail
   | _ -> false
       
 let color_opt_of_file f =
@@ -264,21 +257,19 @@
   match f.data.gfile_availability with
     (_,avail) :: _ ->
       
+      (match f.data.gfile_chunks with
+      | None -> "---"
+      | Some chunks ->
       let rec loop i p n =
-        if i < 0
-        then
-          if n = 0.0
-          then "---"
-          else Printf.sprintf "%5.1f" (p /. n *. 100.0)
+            if i < 0 then
+              if n = 0 then "---"
+              else Printf.sprintf "%5.1f" ((float p) /. (float n) *. 100.0)
         else
-        if CommonGlobals.partial_chunk f.data.gfile_chunks.[i]
-        then
-          if avail.[i] <> (char_of_int 0)
-          then loop (i - 1) (p +. 1.0) (n +. 1.0)
-          else loop (i - 1) p (n +. 1.0)
-        else loop (i - 1) p n
-      in
-      loop ((String.length avail) - 1) 0.0 0.0
+             loop (i - 1)
+               (if CommonGlobals.partial_chunk (VB.get chunks i) then p + 1 
+               else p)
+               (if avail.[i] <> (char_of_int 0) then n + 1 else n) in
+      loop ((String.length avail) - 1) 0 0)
   | _ -> "---"
       
 let string_availability s =
@@ -650,66 +641,50 @@
   let pixmap = GDraw.pixmap ~width:width ~height:height
       ~colormap:(Gdk.Color.get_system_colormap ()) ()
   in
-  let nchunks = String.length chunks in
+  match chunks with
+  | None -> pixmap
+  | Some chunks ->
+      let nchunks = VB.length chunks in
   try 
     match avail with
-      (_,avail) :: _ ->
-        
+       | (_,avail) :: _ ->
         
-        begin
           for i = 0 to (width - 1) do
             let ind = i * (nchunks - 1) / (width - 1) in
-            begin
-              if is_file then
-                if chunks.[ind] >= '2'
-                then pixmap#put_pixmap
-                    ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height
-                    color_green#pixmap
-                else
-                let h = int_of_char (avail.[ind]) in
-                if h = 0
-                then if chunks.[ind] = '0' then
-                    pixmap#put_pixmap
-                      ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height
-                      color_red#pixmap
-                  else
                     pixmap#put_pixmap
                       ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height
-                      color_orange#pixmap
-                else begin
-                    let h = if h >= !!O.availability_max then
-                        0
-                      else (!!O.availability_max - h)
-                    in
+               (if is_file then
+                 match int_of_char(avail.[ind]), VB.get chunks ind with
+                 | _, (VB.State_complete | VB.State_verified) -> 
+                     color_green#pixmap
+
+                 | 0, VB.State_missing -> color_red#pixmap
+
+                 | 0, VB.State_partial -> color_orange#pixmap
+
+                 | h, (VB.State_missing | VB.State_partial) (* h > 0 *) ->
+                      let h = 
+                       if h >= !!O.availability_max then 0
+                       else (!!O.availability_max - h) in
                     let color_blue = !color_blue_relative.(h) in
-                    pixmap#put_pixmap
-                      ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height
                       color_blue#pixmap
-                  end
-              else
-              if avail.[ind] >= '1'
-              then
-                if chunks.[ind] >= '2' then
-                  pixmap#put_pixmap
-                    ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height
-                    color_black#pixmap
-                else
-                  pixmap#put_pixmap
-                    ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height
-                    color_green#pixmap
               else
-              if chunks.[ind] > '2' then
-                pixmap#put_pixmap
-                  ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height
-                  color_orange#pixmap
-              else
-                pixmap#put_pixmap
-                  ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height
+                 match int_of_char(avail.[ind]), VB.get chunks ind with
+                 | 0, VB.State_verified -> color_orange#pixmap
+
+                 | 0, (VB.State_missing | VB.State_partial |
+                       VB.State_complete) -> 
                   color_red#pixmap
-            end
+
+                 | _, (VB.State_complete | VB.State_verified) ->
+                     (* h > 0 *) 
+                     color_black#pixmap
+
+                 | _, (VB.State_missing | VB.State_partial) ->
+                     (* h > 0 *)
+                     color_green#pixmap)
           done;
           pixmap
-        end
     | _ -> raise Not_found  
   with _ ->
       begin

Index: src/gtk/newgui/gui_types.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/gtk/newgui/gui_types.ml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- src/gtk/newgui/gui_types.ml 12 Jul 2005 23:47:33 -0000      1.9
+++ src/gtk/newgui/gui_types.ml 12 Jun 2006 10:02:58 -0000      1.10
@@ -51,7 +51,7 @@
     mutable gfile_all_sources : int;
     mutable gfile_active_sources: int;
     mutable gfile_state : general_state;
-    mutable gfile_chunks : string;
+    mutable gfile_chunks : VerificationBitmap.t option;
     mutable gfile_availability : (int * string) list;
     mutable gfile_download_rate : float;
     mutable gfile_format : format;

Index: src/gtk2/gui/guiMisc.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/gtk2/gui/guiMisc.ml,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- src/gtk2/gui/guiMisc.ml     11 Jun 2006 17:37:38 -0000      1.17
+++ src/gtk2/gui/guiMisc.ml     12 Jun 2006 10:02:59 -0000      1.18
@@ -776,22 +776,12 @@
 let some_is_available availability chunks =
   if !!O.gtk_misc_relative_availability
     then
-      let rec loop i =
-        if i < 0
-          then false
-        else if CommonGlobals.partial_chunk (VerificationBitmap.get chunks i) 
&&
-                  availability.[i] <> (char_of_int 0)
-            then true
-            else loop (i - 1)
-      in
-      loop ((String.length availability) - 1)
+    String2.existsi (fun i a ->
+      CommonGlobals.partial_chunk (VerificationBitmap.get chunks i) &&
+        a <> (char_of_int 0)
+    ) availability
     else
-      let b = ref false in
-      let len = String.length availability in
-      for i = 0 to len - 1 do
-        b := !b or int_of_char availability.[i] <> 0
-      done;
-      !b
+    String2.exists ((<>) (char_of_int 0)) availability
 
 let relative_availability_of avail chunks =
   match chunks with

Index: src/utils/cdk/array2.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/cdk/array2.ml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- src/utils/cdk/array2.ml     22 Apr 2003 22:33:39 -0000      1.1
+++ src/utils/cdk/array2.ml     12 Jun 2006 10:02:59 -0000      1.2
@@ -33,3 +33,32 @@
   done;
   !max_val
   
\ No newline at end of file
+let exists p a =
+  let l = Array.length a in
+  let rec aux i = (i < l) && (p a.(i) || aux (i+1)) in
+  aux 0
+
+let existsi p a =
+  let l = Array.length a in
+  let rec aux i = (i < l) && (p i a.(i) || aux (i+1)) in
+  aux 0
+
+(* based on Array.fold_left code *)
+let fold_lefti f x a =
+  let r = ref x in
+  for i = 0 to Array.length a - 1 do
+    r := f !r i (Array.unsafe_get a i)
+  done;
+  !r
+
+let subarray_fold_lefti f x a firstidx lastidx =
+  let len = Array.length a in
+  assert(firstidx >= 0 && firstidx < len);
+  assert(lastidx >= 0 && lastidx < len);
+  let r = ref x in
+  for i = firstidx to lastidx do
+    r := f !r i (Array.unsafe_get a i)
+  done;
+  !r
+
+

Index: src/utils/cdk/string2.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/cdk/string2.ml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- src/utils/cdk/string2.ml    1 Nov 2004 11:23:02 -0000       1.7
+++ src/utils/cdk/string2.ml    12 Jun 2006 10:02:59 -0000      1.8
@@ -309,3 +309,22 @@
     s.[i] <- f i 
   done;
   s
\ No newline at end of file
+
+let exists p s =
+  let l = String.length s in
+  let rec aux i =
+    i < l && (p s.[i] || aux (i+1)) in
+  aux 0
+
+let existsi p s =
+  let l = String.length s in
+  let rec aux i =
+    i < l && (p i s.[i] || aux (i+1)) in
+  aux 0
+
+let for_all p s =
+  let l = String.length s in
+  let rec aux i =
+    i >= l || p s.[i] && aux (i+1) in
+  aux 0
+

Index: src/utils/cdk/string2.mli
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/cdk/string2.mli,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- src/utils/cdk/string2.mli   4 Jan 2006 14:11:55 -0000       1.8
+++ src/utils/cdk/string2.mli   12 Jun 2006 10:02:59 -0000      1.9
@@ -103,3 +103,6 @@
   
 val map : (char -> 'a) -> string -> 'a array
 val iteri: (int -> char -> unit) -> string -> unit
+val exists: (char -> bool) -> string -> bool
+val existsi: (int -> char -> bool) -> string -> bool
+val for_all: (char -> bool) -> string -> bool




reply via email to

[Prev in Thread] Current Thread [Next in Thread]