ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dick, Brian E." <Brian.D...@FMR.com>
Subject Parsing file. It works but...
Date Fri, 11 Feb 2005 20:24:57 GMT
...there has to be a better way to do this.

I have a file that contains lines like the following.

src1 trg1
src2
src3 trg3

I need to parse the file and send the two values in each line to another
program. When there is only one value on the line, I have to send the
value twice. Here's the target I wrote to parse the file. I looks pretty
ugly. Can anyone simplify this?

<target name="test">
   <loadfile property="list" srcFile="test_list.txt">
      <filterchain>
         <tokenfilter delimoutput=","/>
      </filterchain>
   </loadfile>

   <for list="${list}" param="line">
      <sequential>
         <propertyregex property="source"
                        input="@{line}"
                        regexp="^(.+)\s(.+)$"
                        select="\1"
         />

         <propertyregex property="target"
                        input="@{line}"
                        regexp="^(.+)\s(.+)$"
                        select="\2"
         />

         <if>
            <not>
               <isset property="source"/>
            </not>
            <then>
               <property name="source" value="@{line}"/>
               <property name="target" value="@{line}"/>
            </then>
         </if>

         <echo>Process Source=${source} Target=${target}</echo>

         <var name="source" unset="true"/>
         <var name="target" unset="true"/>
      </sequential>
   </for>
</target>

Thanks,
BEDick

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


Mime
View raw message