org.eclipse.cdt.internal.formatter.scanner
Class Scanner

java.lang.Object
  extended by org.eclipse.cdt.internal.formatter.scanner.SimpleScanner
      extended by org.eclipse.cdt.internal.formatter.scanner.Scanner

public class Scanner
extends SimpleScanner

A scanner operating on a character array and allowing to reposition the scanner.

Since:
4.0

Field Summary
 int eofPosition
           
 char[] source
           
 int startPosition
           
 
Constructor Summary
Scanner()
           
 
Method Summary
 int getCurrentPosition()
          Get the current scanner offset.
 int getCurrentTokenEndPosition()
          Get the inclusive end offset of the current token.
 char[] getCurrentTokenSource()
          Get the text of the current token as a character array.
 int getCurrentTokenStartPosition()
          Get the start offset of the current token.
 int getNextChar()
          Get the next character.
 boolean getNextChar(char c)
          Move to next character iff it is equal to the given expected character.
 int getNextToken()
          Get the next token as token type constant.
 void resetTo(int start, int end)
          Reset scanner to given inclusive start and end offsets
 void setCurrentPosition(int nextCharacterStart)
          Set current scanner offset to given offset.
 void setSource(char[] source)
          Set the source text as character array.
 java.lang.String toString()
          For debugging purposes.
 
Methods inherited from class org.eclipse.cdt.internal.formatter.scanner.SimpleScanner
cleanup, initialize, nextToken, setReuseToken, setSplitPreprocessor
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

source

public char[] source

eofPosition

public int eofPosition

startPosition

public int startPosition
Constructor Detail

Scanner

public Scanner()
Method Detail

setSource

public void setSource(char[] source)
Set the source text as character array.

Parameters:
source - the source text

resetTo

public void resetTo(int start,
                    int end)
Reset scanner to given inclusive start and end offsets

Parameters:
start - inclusive start offset
end - inclusive end offset

getCurrentTokenStartPosition

public int getCurrentTokenStartPosition()
Get the start offset of the current token.

Returns:
the start offset of the current token

getCurrentTokenEndPosition

public int getCurrentTokenEndPosition()
Get the inclusive end offset of the current token.

Returns:
the inclusive end offset of the current token

getCurrentPosition

public int getCurrentPosition()
Get the current scanner offset.

Returns:
the current scanner offset

getNextChar

public int getNextChar()
Get the next character.

Returns:
the next character

getNextChar

public boolean getNextChar(char c)
Move to next character iff it is equal to the given expected character. If the characters do not match, the sanner does not move forward.

Parameters:
c - the expected character
Returns:
true if the next character was the expected character

setCurrentPosition

public void setCurrentPosition(int nextCharacterStart)
Set current scanner offset to given offset.

Parameters:
nextCharacterStart - the desired scanner offset

getCurrentTokenSource

public char[] getCurrentTokenSource()
Get the text of the current token as a character array.

Returns:
the token text

getNextToken

public int getNextToken()
Get the next token as token type constant.

Returns:
the next token type

toString

public java.lang.String toString()
For debugging purposes.

Overrides:
toString in class java.lang.Object