ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Loughran" <stev...@iseran.com>
Subject Re: Replace.java and "\n"
Date Tue, 08 Jan 2002 05:37:49 GMT

----- Original Message -----
From: "Paul Pantages" <ppantage@xtera.com>
To: <ant-dev@jakarta.apache.org>
Sent: Monday, January 07, 2002 7:16 PM
Subject: Replace.java and "\n"


> Hi all,

hello

> I am using ant 1.4.1 on Solaris 2.7, j2dsdk 1.3.1
>
> I was having trouble replacing a token with a value containing newline
> "\n". The replace task was just printing out the two characters
> '\' & 'n' instead of newline.
>
> E.g.,
>    <replace
>      file="filename"
>      token="#BlaBla"
>      value="\n#BlaBla"
>    />
>
> Was insertng \n#BlaBla into my file.
>
> I looked into the source for replace task and at the Replace.processFile()
> method. I see where the \n is supposed to be handled at line 325 or so:
> ...
> String val = stringReplace(value.getText(), "\n", linesep);
> String tok = stringReplace(token.getText(), "\n", linesep);
> ...
>
> The prob. is, the "\n" in the replace call is converted to 0x0a, and
> of course never matches the characters '\','n' in my token or val.

yup

> If I switch the replaced string to "\\n", the replace task does what I
> expect, i.e., switches the "\n" to the unix newline 0x0a.

maybe there is an expectation issue?

>
> ...
> String val = stringReplace(value.getText(), "\\n", linesep);
> String tok = stringReplace(token.getText(), "\\n", linesep);

nope

 ...
> So.... is this is really a bug or am I missing something obvious...?

you are missing something obvious. To put a newline into an xml string you
use &#10; not \n

On the positive note, I am glad that you were willing to go into the source
and fix behaviour which did not match your expectation. If you keep that
soon you will be finding genuine bugs...

-steve


--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message