FileDocCategorySizeDatePackage
LineTokenizer.javaAPI DocApache Ant 1.703241Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.util

LineTokenizer

public class LineTokenizer extends org.apache.tools.ant.ProjectComponent implements Tokenizer
class to tokenize the input as lines seperated by \r (mac style), \r\n (dos/windows style) or \n (unix style)
since
Ant 1.6

Fields Summary
private String
lineEnd
private int
pushed
private boolean
includeDelims
Constructors Summary
Methods Summary
public java.lang.StringgetPostToken()

return
the line ending character(s) for the current line

        if (includeDelims) {
            return "";
        }
        return lineEnd;
    
public java.lang.StringgetToken(java.io.Reader in)
get the next line from the input

param
in the input reader
return
the line excluding /r or /n, unless includedelims is set
exception
IOException if an error occurs reading

        int ch = -1;
        if (pushed != -2) {
            ch = pushed;
            pushed = -2;
        } else {
            ch = in.read();
        }
        if (ch == -1) {
            return null;
        }

        lineEnd = "";
        StringBuffer line = new StringBuffer();

        int state = 0;
        while (ch != -1) {
            if (state == 0) {
                if (ch == '\r") {
                    state = 1;
                } else if (ch == '\n") {
                    lineEnd = "\n";
                    break;
                } else {
                    line.append((char) ch);
                }
            } else {
                state = 0;
                if (ch == '\n") {
                    lineEnd = "\r\n";
                } else {
                    pushed = ch;
                    lineEnd = "\r";
                }
                break;
            }
            ch = in.read();
        }
        if (ch == -1 && state == 1) {
            lineEnd = "\r";
        }

        if (includeDelims) {
            line.append(lineEnd);
        }
        return line.toString();
    
public voidsetIncludeDelims(boolean includeDelims)
attribute includedelims - whether to include the line ending with the line, or to return it in the posttoken default false

param
includeDelims if true include /r and /n in the line


                                         

        
        this.includeDelims = includeDelims;