JIDE 3.5.15

com.jidesoft.editor
Class TextUtils

java.lang.Object
  extended by com.jidesoft.editor.TextUtils

public class TextUtils
extends Object

Class with several utility functions used by the CodeEditor.

Author:
Slava Pestov

Constructor Summary
TextUtils()
           
 
Method Summary
static String createWhiteSpace(int len, int tabSize, boolean replaceTabWithSpaces)
          Creates a string of white space with the specified length.
static String createWhiteSpace(int len, int tabSize, boolean replaceTabWithSpaces, int start)
          Creates a string of white space with the specified length.
static int findMatchingBracket(Document doc, int offset)
          Returns the offset of the bracket matching the one at the specified offset of the document, or -1 if the bracket is unmatched (or if the character is not a bracket).
static int findPreviousOpenBracket(Document doc, int offset)
           
static int findWordEnd(String line, int pos, String noWordDelimiters)
          Locates the end of the word at the specified position.
static int findWordEnd(String line, int pos, String noWordDelimiters, boolean joinNonWordChars)
          Locates the end of the word at the specified position.
static int findWordEnd(String line, int pos, String noWordDelimiters, boolean joinNonWordChars, boolean eatWhitespace)
          Locates the end of the word at the specified position.
static int findWordStart(String line, int pos, String noWordSep)
          Locates the start of the word at the specified position.
static int findWordStart(String line, int pos, String noWordSep, boolean joinNonWordChars)
          Locates the start of the word at the specified position.
static int findWordStart(String line, int pos, String noWordDelimiters, boolean joinNonWordChars, boolean eatWhitespace)
          Locates the start of the word at the specified position.
static String getLeadingWhitespace(String line)
           
static String getLineBreak(int lineBreakType)
           
static boolean isBracket(char c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtils

public TextUtils()
Method Detail

findPreviousOpenBracket

public static int findPreviousOpenBracket(Document doc,
                                          int offset)
                                   throws BadLocationException
Throws:
BadLocationException

findMatchingBracket

public static int findMatchingBracket(Document doc,
                                      int offset)
                               throws BadLocationException
Returns the offset of the bracket matching the one at the specified offset of the document, or -1 if the bracket is unmatched (or if the character is not a bracket).

Parameters:
doc - The document
offset - The offset
Returns:
the offset of the matching bracket in the doc. -1 if no matching bracket found.
Throws:
BadLocationException - If an out-of-bounds access was attempted on the document text

findWordStart

public static int findWordStart(String line,
                                int pos,
                                String noWordSep)
Locates the start of the word at the specified position.

Parameters:
line - The text
pos - The position
noWordSep - Characters that are non-alphanumeric, but should be treated as word characters anyway
Returns:
the index of the first letter of the word.

findWordStart

public static int findWordStart(String line,
                                int pos,
                                String noWordSep,
                                boolean joinNonWordChars)
Locates the start of the word at the specified position.

Parameters:
line - The text
pos - The position
noWordSep - Characters that are non-alphanumeric, but should be treated as word characters anyway
joinNonWordChars - Treat consecutive non-alphanumeric characters as one word
Returns:
the index of the first letter of the word.

findWordStart

public static int findWordStart(String line,
                                int pos,
                                String noWordDelimiters,
                                boolean joinNonWordChars,
                                boolean eatWhitespace)
Locates the start of the word at the specified position.

Parameters:
line - The text
pos - The position
noWordDelimiters - Characters that are non-alphanumeric, but should be treated as word characters anyway
joinNonWordChars - Treat consecutive non-alphanumeric characters as one word
eatWhitespace - Include whitespace at start of word
Returns:
the index of the first letter of the word.

findWordEnd

public static int findWordEnd(String line,
                              int pos,
                              String noWordDelimiters)
Locates the end of the word at the specified position.

Parameters:
line - The text
pos - The position
noWordDelimiters - Characters that are non-alphanumeric, but should be treated as word characters anyway
Returns:
the index of the last letter of the word.

findWordEnd

public static int findWordEnd(String line,
                              int pos,
                              String noWordDelimiters,
                              boolean joinNonWordChars)
Locates the end of the word at the specified position.

Parameters:
line - The text
pos - The position
noWordDelimiters - Characters that are non-alphanumeric, but should be treated as word characters anyway
joinNonWordChars - Treat consecutive non-alphanumeric characters as one word
Returns:
the index of the last letter of the word.

findWordEnd

public static int findWordEnd(String line,
                              int pos,
                              String noWordDelimiters,
                              boolean joinNonWordChars,
                              boolean eatWhitespace)
Locates the end of the word at the specified position.

Parameters:
line - The text
pos - The position
noWordDelimiters - Characters that are non-alphanumeric, but should be treated as word characters anyway
joinNonWordChars - Treat consecutive non-alphanumeric characters as one word
eatWhitespace - Include whitespace at end of word
Returns:
the index of the last letter of the word.

getLeadingWhitespace

public static String getLeadingWhitespace(String line)

createWhiteSpace

public static String createWhiteSpace(int len,
                                      int tabSize,
                                      boolean replaceTabWithSpaces,
                                      int start)
Creates a string of white space with the specified length.

To get a whitespace string tuned to the current buffer's settings, call this method as follows:

myWhitespace = MiscUtilities.createWhiteSpace(myLength,
     (buffer.getBooleanProperty("noTabs") ? 0
     : buffer.getTabSize()));

Parameters:
len - The length
tabSize - The tab size, or 0 if tabs are not to be used
replaceTabWithSpaces - the flag indicating if it will use space instead of tab
start - The start offset, for tab alignment
Returns:
the created string.

createWhiteSpace

public static String createWhiteSpace(int len,
                                      int tabSize,
                                      boolean replaceTabWithSpaces)
Creates a string of white space with the specified length.

To get a whitespace string tuned to the current buffer's settings, call this method as follows:

myWhitespace = TextUtils.createWhiteSpace(myLength,
     (buffer.getBooleanProperty("noTabs") ? 0
     : buffer.getTabSize()));

Parameters:
len - The length
tabSize - The tab size, or 0 if tabs are not to be used
replaceTabWithSpaces - the flag indicating if it will use space instead of tab
Returns:
the created string.

getLineBreak

public static String getLineBreak(int lineBreakType)

isBracket

public static boolean isBracket(char c)

JIDE 3.5.15