Changeset 20047
- Timestamp:
- 2009-07-21T15:17:02+12:00 (14 years ago)
- Location:
- other-projects/trunk/anttasks
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/trunk/anttasks/build.xml
r20041 r20047 110 110 <dcff file="test/dcff3.txt" startTag="fox" leaveTags="true"/> 111 111 112 </target> 112 <!-- test 4 --> 113 <copy file="src/test/dcff.txt" tofile="test/dcff4.txt"/> 114 <dcff file="test/dcff4.txt" startTag="<!--start-->" endTag="<!--end-->"/> 115 116 </target> 113 117 114 118 <target name="test-gpv" depends="test-setup"> -
other-projects/trunk/anttasks/src/org/greenstone/anttasks/DeleteChunkFromFile.java
r17554 r20047 31 31 32 32 private File file = null; 33 private StringstartTag = null;34 private StringendTag = null;33 private Pattern startTag = null; 34 private Pattern endTag = null; 35 35 private boolean leaveTags = false; 36 36 … … 93 93 boolean hasMoreLines = true; 94 94 boolean lookingForStartTag = true; 95 String toDefer = null; 96 95 97 while ( hasMoreLines ) { 96 98 97 try { 98 line = in.readLine(); 99 } catch ( Exception e ) { 100 throw new BuildException( "Error - Couldn't read from the specified file" ); 99 //get the next line - either from the file of the leftovers from the last loop around 100 if ( toDefer != null ) { 101 line = toDefer; 102 toDefer = null; 103 } else { 104 try { 105 line = in.readLine(); 106 } catch ( Exception e ) { 107 throw new BuildException( "Error - Couldn't read from the specified file" ); 108 } 101 109 } 102 110 … … 105 113 } else { 106 114 107 boolean writeLine = lookingForStartTag; 108 115 String toWrite = null; 116 boolean endLine = false; 117 System.out.print("line: " + line ); 109 118 if ( lookingForStartTag ) { 110 if ( line.matches( startTag ) ) { 119 Matcher m = startTag.matcher(line); 120 if ( m.find() ) { 111 121 lookingForStartTag = false; 112 writeLine = leaveTags; 122 toWrite = line.substring(0,leaveTags?m.end():m.start()); 123 toDefer = line.substring(m.end()); 124 System.out.println(" (a)"); 125 } else { 126 toWrite = line; 127 endLine = true; 128 System.out.println(" (b)"); 113 129 } 114 } else { 115 if ( endTag != null && line.matches( endTag ) ) { 130 } else if ( endTag != null ) { 131 Matcher m = endTag.matcher(line); 132 if ( m.find() ) { 116 133 lookingForStartTag = true; 117 writeLine = leaveTags; 134 toDefer = line.substring(leaveTags?m.start():m.end()); 135 System.out.println(" (c)"); 136 } else { 137 System.out.println(" (d)"); 118 138 } 119 139 } 120 140 121 if ( writeLine) {141 if ( toWrite != null ) { 122 142 try { 123 out.write(line); 124 out.newLine(); 143 out.write(toWrite); 144 if ( endLine ) { 145 out.newLine(); 146 } 125 147 } catch ( Exception e ) { 126 148 throw new BuildException( "Error - Couldn't write to the temp file" ); … … 176 198 177 199 public void setStartTag(String st) { 178 this.startTag = st; 200 try { 201 this.startTag = Pattern.compile(st); 202 } catch ( PatternSyntaxException pse ) { 203 throw new BuildException( "Invalid start tag!!" ); 204 } 179 205 } 180 206 181 207 public void setEndTag(String et) { 182 this.endTag = et; 208 try { 209 this.endTag = Pattern.compile(et); 210 } catch ( PatternSyntaxException pse ) { 211 throw new BuildException( "Invalid start tag!!" ); 212 } 183 213 } 184 214 -
other-projects/trunk/anttasks/src/test/dcff.txt
r17554 r20047 13 13 ÑÑÑÑкОй ÑзÑк 14 14 äžæ 15 16 more text 17 b<!--start-->row<!--end-->n 18 even more text
Note:
See TracChangeset
for help on using the changeset viewer.