Package org.htmlparser.lexerapplications.tabby
The Tabby program is a demonstration of how to use the underlying Lexer
classes to perform file I/O.
Tabby | Replace tabs with spaces. |
The Tabby program is a demonstration of how to use the underlying Lexer
classes to perform file I/O. The results could also be achieved with a normal
Reader object but then there wouldn't be anything interesting about this.
The task is to replace tabs with spaces and preserve any indentaion that was a
combination of tabs and spaces. This means honouring the 'tab stops' that would
be used by an editor and not just a global search and replace.
The mechanism used is to keep track of the character offset from the beginning
of a line and when a tab is encountered add spaces till the next tab stop.
At the same time any "\r\n" combinations that are in the file are converted to
simple "\n" characters as found on Unix/Linux systems, and trailing whitespace
at the ends of lines is removed.
The trick is to only write the file if something in the file required changes,
so a boolean variable is kept current with a
true
value indicating
the file needs to be modified.
| © 2005 Derrick Oswald Mai 08, 2008 |
HTML Parser is an open source library released under LGPL. |  |