From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA04526; Thu, 27 May 2004 10:12:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA03801 for ; Thu, 27 May 2004 10:12:20 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mail.fltrp.com ([211.101.185.130]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i4R8CBSH016917 for ; Thu, 27 May 2004 10:12:15 +0200 Received: from kaitiany [129.0.5.6] by mail.fltrp.com with ESMTP (SMTPD32-7.13) id A1502C027A; Thu, 27 May 2004 16:05:36 +0800 From: YANG Shouxun Organization: FLTRP To: caml-list@inria.fr Subject: Re: [Caml-list] unix.chop_extension Date: Thu, 27 May 2004 16:15:17 +0800 User-Agent: KMail/1.6.2 References: <1085429093.6065.336.camel@pelican.wigram> <40B307F7.6060405@baretta.com> In-Reply-To: <40B307F7.6060405@baretta.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200405271615.18042.yangsx@fltrp.com> X-Miltered: at concorde with ID 40B5A2DB.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; shouxun:01 yangsx:01 fltrp:01 caml-list:01 chop:01 2004:99 baretta:01 chop:01 terrible:01 regexps:01 stringent:99 precondition:01 precondition:01 2004:99 basename:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tuesday 25 May 2004 16:46, Alex Baretta wrote: > skaller wrote: > > # Filename.chop_extension "x.y/z";; > > - : string = "x" > > This is a terrible consequence of not having (* functional *) support > for regexps in the language or standard library. The Filename library > uses the very weak functions of the String library to find the rightmost > dot in the filename (* or path *), which is obviously correct only under > a very stringent precondition, which is not the most general possible > precondition for this function. It seems to me that regexp is not necessary to fix this specific problem. Hopefully the following patch will get rid of it. --8<-- --- filename.ml~ 2003-12-17 20:23:26.000000000 +0800 +++ filename.ml 2004-05-27 16:11:08.000000000 +0800 @@ -207,10 +207,11 @@ if n < 0 then invalid_arg "Filename.chop_suffix" else String.sub name 0 n let chop_extension name = - try - String.sub name 0 (String.rindex name '.') - with Not_found -> - invalid_arg "Filename.chop_extension" + let bn = Filename.basename name in + try + String.sub bn 0 (String.rindex bn '.') + with Not_found -> + invalid_arg "Filename.chop_extension" external open_desc: string -> open_flag list -> int -> int = "sys_open" external close_desc: int -> unit = "sys_close" --8<-- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners