From: Bardur A. <sp...@sc...> - 2005-11-15 16:26:08
|
Brian Brunswick wrote: > Hi, thanks for extlib! > > ExtString.String.slice doesn't live up to its documentation of never > raising an exception. It fails to check if ~last is out of range, and > crashes in String.sub. > > Is it best to report bugs here, or in the tracker? > > -- I notice there's been no commit to the CVS with a fix for this even though the bug was reported quite a long time ago, so I'm going to commit this cleaned up and corrected version later today/tomorrow if there are no objections: let clip _min _max x = max _min (min _max x) ;; let slice ?(first=0) ?(last=Sys.max_string_length) s = let i = clip 0 (length s) (if (first<0) then (length s) + first else first) and j = clip 0 (length s) (if (last<0) then (length s) + last else last) in if i>=j || i=length s then create 0 else sub s i (j-i) Btw, John Skaller is correct in that the behavior was intended to be exactly like Python's slice operator. -- Bardur Arantsson <ba...@im...> <ba...@sc...> - And the best part? I didn't learn a thing. |