FileDocCategorySizeDatePackage
Undent.javaAPI DocExample1307Sun Jun 03 22:42:46 BST 2001None

Undent

public class Undent extends Object
Undent - remove leading spaces
author
Ian F. Darwin, ian@darwinsys.com
version
$Id: Undent.java,v 1.2 2001/06/04 01:42:47 ian Exp $

Fields Summary
protected int
nSpaces
the maximum number of spaces to remove.
Constructors Summary
Undent(int n)

		nSpaces = n;
	
Methods Summary
public static voidmain(java.lang.String[] av)

        Undent c = new Undent(5);
        switch(av.length) {
            case 0: c.process(new BufferedReader(
                        new InputStreamReader(System.in))); break;
            default:
		for (int i=0; i<av.length; i++)
			try {
				c.process(new BufferedReader(new FileReader(av[i])));
			} catch (FileNotFoundException e) {
				System.err.println(e);
			}
        }
    
public voidprocess(java.io.BufferedReader is)
print one file, given an open BufferedReader

        try {
            String inputLine;

			//+
            while ((inputLine = is.readLine()) != null) {
				int toRemove = 0;
				for (int i=0; i<nSpaces && i < inputLine.length(); i++)
					if (Character.isSpace(inputLine.charAt(i)))
						++toRemove;
                System.out.println(inputLine.substring(toRemove));
            }
			//-
            is.close();
        } catch (IOException e) {
            System.out.println("IOException: " + e);
        }