Changeset 1628


Ignore:
Timestamp:
10/12/06 15:01:48 (14 years ago)
Author:
curtis
Message:

Add support for removing consecutive blank lines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils/FixEOLSpaces.java

    r953 r1628  
    55import java.io.*; 
    66 
    7 /** Scans text files for end-of-line spaces, and removes them. */ 
     7/** 
     8 * Scans text files for end-of-line spaces or tabs, and 
     9 * multiple consecutive blank lines, and removes them. 
     10 */ 
    811public class FixEOLSpaces { 
    912 
     
    1619      BufferedReader in = new BufferedReader(new FileReader(inFile)); 
    1720      boolean process = false; 
     21      boolean lastBlank = false; 
    1822      while (true) { 
    1923        String line = in.readLine(); 
     
    2327          break; 
    2428        } 
     29        boolean blank = line.trim().equals(""); 
     30        if (blank && lastBlank) { 
     31          // found consecutive blank lines 
     32          process = true; 
     33          break; 
     34        } 
     35        lastBlank = blank; 
    2536      } 
    2637      in.close(); 
     
    3142        File outFile = new File(args[i] + ".tmp"); 
    3243        PrintWriter out = new PrintWriter(new FileWriter(outFile)); 
     44        lastBlank = false; 
    3345        while (true) { 
    3446          String line = in.readLine(); 
     
    4254            line = new String(c, 0, n + 1); 
    4355          } 
    44           out.println(line); 
     56          boolean blank = line.equals(""); 
     57          if (!blank || !lastBlank) out.println(line); 
     58          lastBlank = blank; 
    4559        } 
    4660        out.close(); 
Note: See TracChangeset for help on using the changeset viewer.