From: Bardur A. <sp...@sc...> - 2005-11-16 18:12:39
|
Bardur Arantsson wrote: > 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. > I've committed the above version; with slightly less "spacy" syntax. -- Bardur Arantsson <bar...@TH...> <bar...@TH...> - Me? The 13th Duke of Wimbourne? In a student nurse's hall of residence at three in the morning? With my reputation? ... Bingo! The 13th Duke of Wimbourne, 'The Fast Show' |