ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Ayers" <>
Subject RE: Removing whitespace in the code
Date Tue, 25 Feb 2003 23:31:37 GMT

> From: Nathan Christiansen []
> Sent: Tuesday, February 25, 2003 2:43 PM

> Here is an equivalent expression (PERL Golf):
> perl -p0e 's/\s\s+/ /sg' < src_file.html > dst_file.html

	Here's mine:

perl -lpe "s/\s+/ /g" < src_file.html | \
		perl -lpe "s/^ //" > dest_file.html

> Since the code reduces the entire file to one line, either of 
> these solutions are
> not good for JSP files with scriptlets (line comments 
> suddenly make portions of
> your code commented out.) This could also cause problems for 
> poorly formed
> JavaScript code embedded in the HTML file. (Automatic 
> semicolon insertion uses
> line endings and closing brackets "}".)

	My solution keeps line endings intact, so there should be no problems with per-line comments
hiding code.  However, you may still have problems with space-formatted string constants,
<pre> code, embedded Python (?!), and more, so use at your own risk.

	Note that by removing the "g" from the first perl script, you would just trim lefthand space,
which may be much safer.

> The best approach that I could see in developing a way to do 
> this in ant is by
> writing a custom filterReader to make it happen during the 
> copy task.  This
> filterReader would also be HTML and JSP aware in order to 
> keep the spacing in
> scriptlets, and line terminators JavaScript or Style 
> elements, depending on the
> <param> values passed to it.

	This would pretty much be a necessity for general use, as there are inevitably places where
spaces and/or tabs must be left unmolested.


View raw message