001    /*
002      Copyright (C) 2002 Julien van Malderen
003    
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public License
015      along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
017    
018    package org.objectweb.jac.util.preparse;
019    
020    import java.io.BufferedReader;
021    import java.io.Reader;
022    import java.io.IOException;
023    
024    public class ParseInput extends BufferedReader
025    {
026       String currentLine;
027       boolean modified = false;
028    
029       public ParseInput(Reader in)
030       {
031          super(in);
032       }
033    
034       public ParseInput(Reader in, int sz)
035       {
036          super(in, sz);
037       }
038    
039       /**
040        * Returns the next line from the input
041        */
042       public String readLine()
043          throws IOException
044       {
045          if (modified)
046             modified = false;
047          else
048             currentLine = super.readLine();
049          return currentLine;
050       }
051    
052       public boolean isModified()
053       {
054          return modified;
055       }
056    
057       /**
058        * Skips input until a token is found.
059        * @param token skip until this string is found in the input
060        */
061       public String skipTo(int i, String token)
062          throws IOException
063       {
064          //System.out.println("skipping until "+token);
065          String result = new String();
066          do
067          {
068             int lineLength = currentLine.length();
069             
070             int begin = i;
071             int end;
072             
073             for (end = token.length() + i; end <= lineLength; begin++, end++)
074             {
075                if (currentLine.substring(begin, end).equals(token))
076                {
077                   //result += currentLine.substring(i, end);
078                   currentLine = currentLine.substring(end);
079                   modified = true;
080                   return result;
081                }
082             }
083             //System.out.println("skipping: "+currentLine);
084             //result += currentLine.substring(i);
085             result += '\n';
086             i = 0;
087          }
088          while (readLine() != null);
089          return result;
090       }
091    }