org.eclipse.cdt.internal.ui.text
Class CWordFinder

java.lang.Object
  extended by org.eclipse.cdt.internal.ui.text.CWordFinder

public class CWordFinder
extends java.lang.Object

This is a helper class for the text editor to be able to determine, given a particular offset in a document, various candidates segments for things like context help, proposals and hovering.


Constructor Summary
CWordFinder()
           
 
Method Summary
static int countLFs(java.lang.String s)
          Searches for line feed symbols in string.
static org.eclipse.jface.text.IRegion findFunction(org.eclipse.jface.text.IDocument document, int offset)
          This method will determine the region for the name of the function within which the current offset is contained.
static org.eclipse.jface.text.IRegion findWord(org.eclipse.jface.text.IDocument document, int offset)
          This method determines for a given offset into a given document what the region is which defines the current word.
static boolean hasCBraces(java.lang.String s)
          Checks whether the string contains any C-block delimiters ( { } )
static boolean isGlobal(org.eclipse.jface.text.IDocument document, int offset)
          This method will determine whether current offset is contained in any function's body or it's outside it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CWordFinder

public CWordFinder()
Method Detail

findWord

public static org.eclipse.jface.text.IRegion findWord(org.eclipse.jface.text.IDocument document,
                                                      int offset)
This method determines for a given offset into a given document what the region is which defines the current word. A word is defined as the set of non "C" identifiers. So assuming that ! indicated the current cursor postion: !afunction(int a, int b) --> word = length 0 afunc!tion(int a, int b) --> word = afunction afunction!(int a, int b) --> word = afunction afunction(!int a, int b) --> word = length 0 afunction(int a,! int b) --> word = length 0 afunction(!) --> word = length 0

Parameters:
document - The document to be examined
offset - The offset into the document where a word should be idendified.
Returns:
The region defining the current word, which may be a region of length 0 if the offset is not in a word, or null if there is an error accessing the docment data.

findFunction

public static org.eclipse.jface.text.IRegion findFunction(org.eclipse.jface.text.IDocument document,
                                                          int offset)
This method will determine the region for the name of the function within which the current offset is contained.

Parameters:
document - The document to be examined
offset - The offset into the document where a word should be idendified.
Returns:
The region defining the current word, which may be a region of length 0 if the offset is not in a function, or null if there is an error accessing the docment data.

isGlobal

public static boolean isGlobal(org.eclipse.jface.text.IDocument document,
                               int offset)
This method will determine whether current offset is contained in any function's body or it's outside it.

Parameters:
document - The document to be examined
offset - The offset into the document
Returns:
true if there is no function body around offset false otherwise

countLFs

public static int countLFs(java.lang.String s)
Searches for line feed symbols in string. First met '\r' or '\n' is treated as LF symbol

Parameters:
s - string to search in.
Returns:
number of LFs met.

hasCBraces

public static boolean hasCBraces(java.lang.String s)
Checks whether the string contains any C-block delimiters ( { } )

Parameters:
s - text to check
Returns:
true if curled brace found.