diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2002-12-18 16:02:09 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2002-12-18 16:02:09 +0000 |
commit | 2375b0413acc1f3e6659fc110c13bcc061cd320d (patch) | |
tree | 4661b764b6caa774672a30e7b7baf762293ae0b6 /perl_checker.src/common.ml | |
parent | b852ba8ae186c776d03a44e4a63179a633aaeb52 (diff) | |
download | perl_checker-2375b0413acc1f3e6659fc110c13bcc061cd320d.tar perl_checker-2375b0413acc1f3e6659fc110c13bcc061cd320d.tar.gz perl_checker-2375b0413acc1f3e6659fc110c13bcc061cd320d.tar.bz2 perl_checker-2375b0413acc1f3e6659fc110c13bcc061cd320d.tar.xz perl_checker-2375b0413acc1f3e6659fc110c13bcc061cd320d.zip |
new features including checking methods being available and unused functions
Diffstat (limited to 'perl_checker.src/common.ml')
-rw-r--r-- | perl_checker.src/common.ml | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/perl_checker.src/common.ml b/perl_checker.src/common.ml index 9d21a48..44e63fd 100644 --- a/perl_checker.src/common.ml +++ b/perl_checker.src/common.ml @@ -496,10 +496,6 @@ let adjustModDown m n = n - (n mod m) let adjustModUp m n = adjustModDown m (n + m - 1) -let hashtbl_set h k v = - Hashtbl.remove h k; - Hashtbl.add h k v - let hashtbl_find f h = let r = ref None in Hashtbl.iter (fun v c -> if f v c then r := Some v) h ; @@ -507,11 +503,20 @@ let hashtbl_find f h = | Some v -> v | None -> raise Not_found -let hashtbl_filter f h = - Hashtbl.iter (fun v c -> hashtbl_set h v (f v c)) h +let hashtbl_map f h = Hashtbl.iter (fun v c -> Hashtbl.replace h v (f v c)) h + +let hashtbl_values h = Hashtbl.fold (fun _ v l -> v :: l) h [] +let hashtbl_keys h = Hashtbl.fold (fun k _ l -> k :: l) h [] +let hashtbl_to_list h = Hashtbl.fold (fun k v l -> (k,v) :: l) h [] + +let hashtbl_collect f h = + rev (Hashtbl.fold (fun k v l -> rev_append (f k v) l) h []) -let hashtbl_to_list h = - Hashtbl.fold (fun k v l -> (k,v) :: l) h [] +let hashtbl_exists f h = + try + Hashtbl.iter (fun v c -> if f v c then raise Found) h ; + false + with Found -> true let array_shift a = Array.sub a 1 (Array.length a - 1) let array_last_n n a = @@ -677,7 +682,10 @@ let rec times e = function | n -> e :: times e (n-1) let skip_n_char_ beg end_ s = - String.sub s beg (String.length s - beg - end_) + let full_len = String.length s in + if beg < full_len && full_len - beg - end_ > 0 + then String.sub s beg (full_len - beg - end_) + else "" let skip_n_char n s = skip_n_char_ n 0 s let rec non_index_from s beg c = |