KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > util > preparse > ParseInput


1 /*
2   Copyright (C) 2002 Julien van Malderen
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.util.preparse;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.Reader JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 public class ParseInput extends BufferedReader JavaDoc
25 {
26    String JavaDoc currentLine;
27    boolean modified = false;
28
29    public ParseInput(Reader JavaDoc in)
30    {
31       super(in);
32    }
33
34    public ParseInput(Reader JavaDoc in, int sz)
35    {
36       super(in, sz);
37    }
38
39    /**
40     * Returns the next line from the input
41     */

42    public String JavaDoc readLine()
43       throws IOException JavaDoc
44    {
45       if (modified)
46          modified = false;
47       else
48          currentLine = super.readLine();
49       return currentLine;
50    }
51
52    public boolean isModified()
53    {
54       return modified;
55    }
56
57    /**
58     * Skips input until a token is found.
59     * @param token skip until this string is found in the input
60     */

61    public String JavaDoc skipTo(int i, String JavaDoc token)
62       throws IOException JavaDoc
63    {
64       //System.out.println("skipping until "+token);
65
String JavaDoc result = new String JavaDoc();
66       do
67       {
68          int lineLength = currentLine.length();
69          
70          int begin = i;
71          int end;
72          
73          for (end = token.length() + i; end <= lineLength; begin++, end++)
74          {
75             if (currentLine.substring(begin, end).equals(token))
76             {
77                //result += currentLine.substring(i, end);
78
currentLine = currentLine.substring(end);
79                modified = true;
80                return result;
81             }
82          }
83          //System.out.println("skipping: "+currentLine);
84
//result += currentLine.substring(i);
85
result += '\n';
86          i = 0;
87       }
88       while (readLine() != null);
89       return result;
90    }
91 }
92
Popular Tags