From: Richard J. <ri...@an...> - 2004-06-23 14:31:01
|
First of all a bug: unsafe_get isn't exported by ExtString.String. Here are a couple of functions for ExtString.String: let for_all f str = let len = length str in let rec loop i = if i = len then true else ( let c = unsafe_get str i in if not (f c) then false else loop (i+1) ) in loop 0 let exists f str = let len = length str in let rec loop i = if i = len then false else ( let c = unsafe_get str i in if f c then true else loop (i+1) ) in loop 0 In particular, this lets you write: let string_is_whitespace = String.for_all isspace [Assuming you're using an ASCII-compatible encoding and you've defined a suitable isspace function - see earlier discussion about that.] Rich. -- Richard Jones. http://www.annexia.org/ http://www.j-london.com/ Merjis Ltd. http://www.merjis.com/ - improving website return on investment Learning Objective CAML for C, C++, Perl and Java programmers: http://www.merjis.com/richj/computers/ocaml/tutorial/ |