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 LAA10930; Thu, 27 May 2004 11:47:28 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA11081 for ; Thu, 27 May 2004 11:47:27 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i4R9lOEV001478 for ; Thu, 27 May 2004 11:47:25 +0200 Received: from [192.168.1.200] (ppp114-11.lns1.syd3.internode.on.net [150.101.114.11]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i4R9l5Zq052609; Thu, 27 May 2004 19:17:11 +0930 (CST) Subject: Re: [Caml-list] unix.chop_extension From: skaller Reply-To: skaller@users.sourceforge.net To: YANG Shouxun Cc: caml-list In-Reply-To: <200405271615.18042.yangsx@fltrp.com> References: <1085429093.6065.336.camel@pelican.wigram> <40B307F7.6060405@baretta.com> <200405271615.18042.yangsx@fltrp.com> Content-Type: text/plain Message-Id: <1085651225.32106.371.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 27 May 2004 19:47:05 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 40B5B92C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 chop:01 sourceforge:01 2004:99 shouxun:01 basename:01 chop:01 basename:01 hackery:01 discards:01 jpg':99 filetype:01 9660:01 glebe:01 apps:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 2004-05-27 at 18:15, YANG Shouxun wrote: > + let bn = Filename.basename name in > + try > + String.sub bn 0 (String.rindex bn '.') > + with Not_found -> > + invalid_arg "Filename.chop_extension" But this code returns only the basename with extension chopped! You actually need this: let xchop_extension f = concat (dirname f) (chop_extension (basename f)) but the problem with that is it doesn't just chop the extension .. it also adds a './' to the start of the filename if it didn't have a directory prefix. So I actually wrote that and then stripped any leading ./ off .. which is not generally useful, because one might wish to preserve that info. It can be fixed by "even worse hackery" calling is_implicit and is_relative before and after the concatenation, and adjusting the result to preserve those properties. The right way to fix this is to rindex for "/" first, and limit the scan for "." by the result. BTW: many Win98 apps including IE gets this totally wrong :( Grrrr.... It scans for the FIRST "." and discards the rest of the filename after the second one. When I save 'x.y.jpg' I actually save 'x.y' and the filetype is lost. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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