Trim leading spaces line by line

View: New views
12 Messages — Rating Filter:   Alert me  

Trim leading spaces line by line

by Felix Dorner-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey,

I prefer my xml files to look nice, so I indent multi-line-echoes (these go to a file). Is there a simple ant way to remove all the spaces that were caused by the indentation afterwards?

Felix

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


RE: Trim leading spaces line by line

by Felix Dorner-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I found the solution my self in the ant manual:

<move file="${source}" tofile="${dest}">
        <filterchain>
            <tokenfilter>
                 <deletecharacters chars="\t"/>
                   <trim/>
                   <ignoreblank/>
            </tokenfilter>
        </filterchain>
</move>

It would be nice to do this on-the-fly, so that source and dest are the same. Is this possible somehow?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


RE: Trim leading spaces line by line

by Harnack Frank-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Felix,

try this:

<replaceregexp
        file="xyz.txt"
        match="\s*"
        replace=""
        byline="true"
/>

Regards

Frank


-----Original Message-----
From: Felix Dorner [mailto:FDorner@...]
Sent: Monday, March 09, 2009 2:35 PM
To: Ant Users List
Subject: RE: Trim leading spaces line by line

I found the solution my self in the ant manual:

<move file="${source}" tofile="${dest}">
        <filterchain>
            <tokenfilter>
                 <deletecharacters chars="\t"/>
                   <trim/>
                   <ignoreblank/>
            </tokenfilter>
        </filterchain>
</move>

It would be nice to do this on-the-fly, so that source and dest are the
same. Is this possible somehow?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@... For additional
commands, e-mail: user-help@...


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Trim leading spaces line by line

by Francis Galiegue-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Le mardi 10 mars 2009, Harnack Frank a écrit :
> Hello Felix,
>
> try this:
>
> <replaceregexp
> file="xyz.txt"
> match="\s*"

Err... "^\s*" would be better. If there's no leading space, the first series
of spaces will be replaced by nothing instead.


--
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 6 83 87 78 75
Tel : +33 (0) 1 78 94 55 52
fge@...
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


RE: Trim leading spaces line by line

by Harnack Frank-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Francis,

first I thought, you were right, but it works with "\s*".

"\s+" would not.

But "^\s+" or "^\s*" works too.

Regards

Frank

-----Original Message-----
From: Francis Galiegue [mailto:fge@...]
Sent: Tuesday, March 10, 2009 9:19 AM
To: Ant Users List
Subject: Re: Trim leading spaces line by line

Le mardi 10 mars 2009, Harnack Frank a écrit :
> Hello Felix,
>
> try this:
>
> <replaceregexp
> file="xyz.txt"
> match="\s*"

Err... "^\s*" would be better. If there's no leading space, the first series of spaces will be replaced by nothing instead.


--
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 6 83 87 78 75
Tel : +33 (0) 1 78 94 55 52
fge@...
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Parent Message unknown RV: Trim leading spaces line by line

by Felix Dorner-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Heya,

I confirm that both alternatives work. However, I'm more confident
with "^\s*", and don't see why "\s*" works...
 
Felix
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


RE: Trim leading spaces line by line

by Harnack Frank-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Felix,

I'm more confident with "^\s*" (or better "^\s+") too.

I prefer "^\s+", because it only matches with really existing spaces.

Maybe "\s*" works like this:

- Not existing whitespaces at the beginning of the line matches with
"\s*".
- The not existing whitespaces are replaced with "".
- Nothing is done.

Regards

Frank

-----Original Message-----
From: Felix Dorner [mailto:FDorner@...]
Sent: Tuesday, March 10, 2009 10:53 AM
To: Ant Users List
Subject: RV: Trim leading spaces line by line

Heya,

I confirm that both alternatives work. However, I'm more confident with
"^\s*", and don't see why "\s*" works...
 
Felix
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@... For additional
commands, e-mail: user-help@...


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Trim leading spaces line by line

by Francis Galiegue-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Le mardi 10 mars 2009, Harnack Frank a écrit :

> Hello Felix,
>
> I'm more confident with "^\s*" (or better "^\s+") too.
>
> I prefer "^\s+", because it only matches with really existing spaces.
>
> Maybe "\s*" works like this:
>
> - Not existing whitespaces at the beginning of the line matches with
> "\s*".
> - The not existing whitespaces are replaced with "".
> - Nothing is done.
>

Exactly. The "*" means "0 or more". The regex engine will stop at the first
occurence, and "\s*" means "find 0 spaces or more". Anywhere in the line
where there is 0 or more spaces will match, even lines without no leading
space-like characters.

So, I was wrong. The only benefit of anchoring the regex with ^, like I
suggested, is that most regex engines know that such a regex won't match
anywhere other than the beginning of a line. But this has no influence in
this particular case.

Sorry for the misguided advice,
--
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 6 83 87 78 75
Tel : +33 (0) 1 78 94 55 52
fge@...
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Remove trailing spaces from a string?

by Scott Stark-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi all, I see Ant tasks that can do string substitution in a file. Is there
any way to do that in a simple string? I want to remove trailing spaces
from property values.

The reason I ask is that we use properties files to specify property values
such as file names. Occasionally someone will put an extra space at the end
of a file name, which is impossible to see in a text editor, but the extra
space can cause the build to fail.

Thanks,

Scott Stark

Re: Remove trailing spaces from a string?

by Scot P. Floess-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Ant Contrib has a PropertyRedgex task you can use...

Or you could definitely do something with scripting...like beanshell...

On Mon, 22 Jun 2009, Scott Stark wrote:

>
> Hi all, I see Ant tasks that can do string substitution in a file. Is there
> any way to do that in a simple string? I want to remove trailing spaces
> from property values.
>
> The reason I ask is that we use properties files to specify property values
> such as file names. Occasionally someone will put an extra space at the end
> of a file name, which is impossible to see in a text editor, but the extra
> space can cause the build to fail.
>
> Thanks,
>
> Scott Stark

Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-890-8117 (Work)

Chief Architect JPlate   http://sourceforge.net/projects/jplate
Chief Architect JavaPIM  http://sourceforge.net/projects/javapim

Architect Keros          http://sourceforge.net/projects/keros

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Remove trailing spaces from a string?

by Scott Stark-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Ant Contrib has a PropertyRedgex task you can use...

Sorry, I don't see anything called that in ant-contrib. Is there another
name for it?

thanks,
Scott

Re: Remove trailing spaces from a string?

by Scot P. Floess-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Sorry - type-o...

PropertyRegex - its a link under the Property Tasks:

http://ant-contrib.sourceforge.net/tasks/tasks/propertyregex.html


On Mon, 22 Jun 2009, Scott Stark wrote:

>> Ant Contrib has a PropertyRedgex task you can use...
>
> Sorry, I don't see anything called that in ant-contrib. Is there another
> name for it?
>
> thanks,
> Scott
>

Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-890-8117 (Work)

Chief Architect JPlate   http://sourceforge.net/projects/jplate
Chief Architect JavaPIM  http://sourceforge.net/projects/javapim

Architect Keros          http://sourceforge.net/projects/keros

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...