FileDocCategorySizeDatePackage
DeTab.javaAPI DocExample1477Sun Feb 22 15:16:40 GMT 2004None

DeTab

public class DeTab extends Object
detab- replace blanks by tabs and blanks.
author
Ian F. Darwin, http://www.darwinsys.com/
version
$Id: DeTab.java,v 1.3 2004/02/22 21:16:39 ian Exp $

Fields Summary
Tabs
ts
Constructors Summary
public DeTab(int n)

		ts = new Tabs(n);
	
public DeTab()

		ts = new Tabs();
	
Methods Summary
public voiddetab(java.io.BufferedReader is, java.io.PrintWriter out)
detab one file (replace tabs with spaces)

param
is - the file to be processed
param
out - the updated file

		String line;
		char c;
		int col;
		while ((line = is.readLine()) != null) {
			out.println(detabLine(line));
		}
	
public java.lang.StringdetabLine(java.lang.String line)
detab one line (replace tabs with spaces)

param
line - the line to be processed
return
the updated line

		char c;
		int col;
		StringBuffer sb = new StringBuffer();
		col = 0;
		for (int i = 0; i < line.length(); i++) {
			// Either ordinary character or tab.
			if ((c = line.charAt(i)) != '\t") {
				sb.append(c); // Ordinary
				++col;
				continue;
			}
			do { // Tab, expand it, must put >=1 space
				sb.append(' ");
			} while (!ts.isTabStop(++col));
		}
		return sb.toString();
	
public static voidmain(java.lang.String[] argv)

		DeTab dt = new DeTab(8);
		dt.detab(new BufferedReader(new InputStreamReader(System.in)),
				new PrintWriter(System.out));