Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.gjt.sp.jedit
Class TextUtilities

    java.lang.Object
      org.gjt.sp.jedit.TextUtilities

    public class TextUtilities

extends java.lang.Object

Contains several text manipulation methods.

- Bracket matching
- Word start and end offset calculation
- String comparison
- Converting tabs to spaces and vice versa
- Wrapping text
- String case conversion

Field Summary
`static int` | `BRACKET_MATCH_LIMIT`
`static int` | `LOWER_CASE`
`static int` | `MIXED`
`static int` | `SYMBOL`
`static int` | `TITLE_CASE`
`static int` | `UPPER_CASE`
`static int` | `WHITESPACE`
`static int` | `WORD_CHAR`

Constructor Summary
`TextUtilities()`

Method Summary
`static java.lang.String` | `escapeText(java.lang.String text)` Escapes a given string for use in a java.util.regex pattern.
`static int` | `findMatchingBracket(JEditBuffer buffer, int line, int offset)` Returns the offset of the bracket matching the one at the specified offset of the buffer, or -1 if the bracket is unmatched (or if the character is not a bracket).
`static int` | `findWordEnd(java.lang.CharSequence line, int pos, java.lang.String noWordSep)` Locates the end of the word at the specified position.
`static int` | `findWordEnd(java.lang.CharSequence line, int pos, java.lang.String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace)` Locates the end of the word at the specified position.
`static int` | `findWordEnd(java.lang.String line, int pos, java.lang.String noWordSep)` Locates the end of the word at the specified position.
`static int` | `findWordEnd(java.lang.String line, int pos, java.lang.String noWordSep, boolean joinNonWordChars)` Locates the end of the word at the specified position.
`static int` | `findWordEnd(java.lang.String line, int pos, java.lang.String noWordSep, boolean joinNonWordChars, boolean eatWhitespace)` Locates the end of the word at the specified position.
`static int` | `findWordEnd(java.lang.String line, int pos, java.lang.String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace)` Locates the end of the word at the specified position.
`static int` | `findWordStart(java.lang.CharSequence line, int pos, java.lang.String noWordSep)` Locates the start of the word at the specified position.
`static int` | `findWordStart(java.lang.CharSequence line, int pos, java.lang.String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace)` Locates the start of the word at the specified position.
`static int` | `findWordStart(java.lang.CharSequence line, int pos, java.lang.String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace, boolean eatOnlyAfterWord)` Locates the start of the word at the specified position.
`static int` | `findWordStart(java.lang.String line, int pos, java.lang.String noWordSep)` Locates the start of the word at the specified position.
`static int` | `findWordStart(java.lang.String line, int pos, java.lang.String noWordSep, boolean joinNonWordChars)` Locates the start of the word at the specified position.
`static int` | `findWordStart(java.lang.String line, int pos, java.lang.String noWordSep, boolean joinNonWordChars, boolean eatWhitespace)` Locates the start of the word at the specified position.
`static int` | `findWordStart(java.lang.String line, int pos, java.lang.String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace)` Locates the start of the word at the specified position.
`static java.lang.String` | `format(java.lang.String text, int maxLineLength, int tabSize)` Formats the specified text by merging and breaking lines to the specified width.
`static int` | `getCharType(char ch, java.lang.String noWordSep)` Returns the type of the char.
`static char` | `getComplementaryBracket(char ch, boolean[] direction)` Given an opening bracket, return the corresponding closing bracket and store true in `direction[0]`.
`static int` | `getStringCase(java.lang.CharSequence str)` Returns if the specified string is all upper case, all lower case, or title case (first letter upper case, rest lower case).
`static int` | `getStringCase(java.lang.String str)` Returns if the specified string is all upper case, all lower case, or title case (first letter upper case, rest lower case).
`static Token` | `getTokenAtOffset(Token tokens, int offset)` Returns the token that contains the specified offset.
`static int` | `ignoringWhitespaceIndex(java.lang.String str, int index)` Inverse of `indexIgnoringWhitespace()`.
`static int` | `indexIgnoringWhitespace(java.lang.String str, int index)` Inverse of `ignoringWhitespaceIndex()`.
`static void` | `indexIgnoringWhitespace(java.lang.String text, int maxLineLength, int tabSize, java.lang.StringBuffer buf)`
`static java.lang.String` | `join(java.util.Collection<?> c, java.lang.String delim)` Similar to perl's join() method on lists, but works with all collections.
`static java.lang.String` | `spacesToTabs(java.lang.String in, int tabSize)` Converts consecutive spaces to tabs in the specified string.
`static java.lang.String` | `tabsToSpaces(java.lang.String in, int tabSize)` Converts tabs to consecutive spaces in the specified string.
`static java.lang.String` | `toTitleCase(java.lang.String str)` Converts the specified string to title case, by capitalizing the first letter.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### BRACKET_MATCH_LIMIT

    public static final int BRACKET_MATCH_LIMIT

See Also:
  Constant Field Values

### WHITESPACE

    public static final int WHITESPACE

See Also:
  Constant Field Values

### WORD_CHAR

    public static final int WORD_CHAR

See Also:
  Constant Field Values

### SYMBOL

    public static final int SYMBOL

See Also:
  Constant Field Values

### MIXED

    public static final int MIXED

See Also:
  Constant Field Values

### LOWER_CASE

    public static final int LOWER_CASE

See Also:
  Constant Field Values

### UPPER_CASE

    public static final int UPPER_CASE

See Also:
  Constant Field Values

### TITLE_CASE

    public static final int TITLE_CASE

See Also:
  Constant Field Values

Constructor Detail

### TextUtilities

    public TextUtilities()

Method Detail

### getTokenAtOffset

    public static Token getTokenAtOffset(Token tokens,
                                         int offset)

  Returns the token that contains the specified offset.

  Parameters:
    `tokens` - The token list
    `offset` - The offset
  Since:
    jEdit 4.0pre3

### getComplementaryBracket

    public static char getComplementaryBracket(char ch,
                                               boolean[] direction)

  Given an opening bracket, return the corresponding closing bracket and store true in `direction[0]`. Given a closing bracket, return the corresponding opening bracket and store false in `direction[0]`. Otherwise, return `\0`.

  Since:
    jEdit 4.3pre2

### findMatchingBracket

    public static int findMatchingBracket(JEditBuffer buffer,
                                          int line,
                                          int offset)

  Returns the offset of the bracket matching the one at the specified offset of the buffer, or -1 if the bracket is unmatched (or if the character is not a bracket).

  Parameters:
    `buffer` - The buffer
    `line` - The line
    `offset` - The offset within that line
  Since:
    jEdit 2.6pre1

### join

    public static java.lang.String join(java.util.Collection<?> c,
                                        java.lang.String delim)

  Similar to perl's join() method on lists, but works with all collections.

  Parameters:
    `c` - An iterable collection of Objects
    `delim` - a string to put between each object
  Returns:
    a joined toString() representation of the collection
  Since:
    jedit 4.3pre3

### findWordStart

    public static int findWordStart(java.lang.String line,
                                    int pos,
                                    java.lang.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

### findWordStart

    public static int findWordStart(java.lang.CharSequence line,
                                    int pos,
                                    java.lang.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
  Since:
    jEdit 4.3pre15

### findWordStart

    public static int findWordStart(java.lang.String line,
                                    int pos,
                                    java.lang.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
  Since:
    jEdit 4.2pre5

### findWordStart

    public static int findWordStart(java.lang.String line,
                                    int pos,
                                    java.lang.String noWordSep,
                                    boolean joinNonWordChars,
                                    boolean eatWhitespace)

  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
    `eatWhitespace` - Include whitespace at start of word
  Since:
    jEdit 4.1pre2

### findWordStart

    public static int findWordStart(java.lang.String line,
                                    int pos,
                                    java.lang.String noWordSep,
                                    boolean joinNonWordChars,
                                    boolean camelCasedWords,
                                    boolean eatWhitespace)

  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
    `camelCasedWords` - Treat "camelCased" parts as words
    `eatWhitespace` - Include whitespace at start of word
  Since:
    jEdit 4.3pre10

### findWordStart

    public static int findWordStart(java.lang.CharSequence line,
                                    int pos,
                                    java.lang.String noWordSep,
                                    boolean joinNonWordChars,
                                    boolean camelCasedWords,
                                    boolean eatWhitespace)

  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
    `camelCasedWords` - Treat "camelCased" parts as words
    `eatWhitespace` - Include whitespace at start of word
  Since:
    jEdit 4.3pre15

### findWordStart

    public static int findWordStart(java.lang.CharSequence line,
                                    int pos,
                                    java.lang.String noWordSep,
                                    boolean joinNonWordChars,
                                    boolean camelCasedWords,
                                    boolean eatWhitespace,
                                    boolean eatOnlyAfterWord)

  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
    `camelCasedWords` - Treat "camelCased" parts as words
    `eatWhitespace` - Include whitespace at start of word
    `eatOnlyAfterWord` - Eat only whitespace after a word, in effect this finds actual word starts even if eating
  Since:
    jEdit 4.4pre1

### findWordEnd

    public static int findWordEnd(java.lang.String line,
                                  int pos,
                                  java.lang.String noWordSep)

  Locates the end 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

### findWordEnd

    public static int findWordEnd(java.lang.CharSequence line,
                                  int pos,
                                  java.lang.String noWordSep)

  Locates the end 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
  Since:
    jEdit 4.3pre15

### findWordEnd

    public static int findWordEnd(java.lang.String line,
                                  int pos,
                                  java.lang.String noWordSep,
                                  boolean joinNonWordChars)

  Locates the end 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
  Since:
    jEdit 4.1pre2

### findWordEnd

    public static int findWordEnd(java.lang.String line,
                                  int pos,
                                  java.lang.String noWordSep,
                                  boolean joinNonWordChars,
                                  boolean eatWhitespace)

  Locates the end 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
    `eatWhitespace` - Include whitespace at end of word
  Since:
    jEdit 4.2pre5

### findWordEnd

    public static int findWordEnd(java.lang.String line,
                                  int pos,
                                  java.lang.String noWordSep,
                                  boolean joinNonWordChars,
                                  boolean camelCasedWords,
                                  boolean eatWhitespace)

  Locates the end 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
    `camelCasedWords` - Treat "camelCased" parts as words
    `eatWhitespace` - Include whitespace at end of word
  Since:
    jEdit 4.3pre10

### findWordEnd

    public static int findWordEnd(java.lang.CharSequence line,
                                  int pos,
                                  java.lang.String noWordSep,
                                  boolean joinNonWordChars,
                                  boolean camelCasedWords,
                                  boolean eatWhitespace)

  Locates the end 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
    `camelCasedWords` - Treat "camelCased" parts as words
    `eatWhitespace` - Include whitespace at end of word
  Since:
    jEdit 4.3pre15

### getCharType

    public static int getCharType(char ch,
                                  java.lang.String noWordSep)

  Returns the type of the char.

  Parameters:
    `ch` - the character
    `noWordSep` - Characters that are non-alphanumeric, but should be treated as word characters anyway, it must not be null
  Returns:
    the type of the char : `WHITESPACE`, `WORD_CHAR`, `SYMBOL`
  Since:
    jEdit 4.4pre1

### spacesToTabs

    public static java.lang.String spacesToTabs(java.lang.String in,
                                                int tabSize)

  Converts consecutive spaces to tabs in the specified string.

  Parameters:
    `in` - The string
    `tabSize` - The tab size

### tabsToSpaces

    public static java.lang.String tabsToSpaces(java.lang.String in,
                                                int tabSize)

  Converts tabs to consecutive spaces in the specified string.

  Parameters:
    `in` - The string
    `tabSize` - The tab size

### format

    public static java.lang.String format(java.lang.String text,
                                          int maxLineLength,
                                          int tabSize)

  Formats the specified text by merging and breaking lines to the specified width.

  Parameters:
    `text` - The text
    `maxLineLength` - The maximum line length
    `tabSize` - The tab size

### indexIgnoringWhitespace

    public static int indexIgnoringWhitespace(java.lang.String str,
                                              int index)

  Inverse of `ignoringWhitespaceIndex()`.

  Parameters:
    `str` - a string (not an empty string)
    `index` - The index
  Returns:
    The number of non-whitespace characters that precede the index.
  Since:
    jEdit 4.3pre2

### ignoringWhitespaceIndex

    public static int ignoringWhitespaceIndex(java.lang.String str,
                                              int index)

  Inverse of `indexIgnoringWhitespace()`.

  Parameters:
    `str` - a string (not an empty string)
    `index` - The index
  Returns:
    The index into the string where the number of non-whitespace characters that precede the index is count.
  Since:
    jEdit 4.3pre2

### getStringCase

    public static int getStringCase(java.lang.CharSequence str)

  Returns if the specified string is all upper case, all lower case, or title case (first letter upper case, rest lower case).

  Parameters:
    `str` - The string
  Since:
    jEdit 4.4pre1

### getStringCase

    public static int getStringCase(java.lang.String str)

  Returns if the specified string is all upper case, all lower case, or title case (first letter upper case, rest lower case).

  Parameters:
    `str` - The string
  Since:
    jEdit 4.0pre1

### toTitleCase

    public static java.lang.String toTitleCase(java.lang.String str)

  Converts the specified string to title case, by capitalizing the first letter.

  Parameters:
    `str` - The string
  Since:
    jEdit 4.0pre1

### escapeText

    public static java.lang.String escapeText(java.lang.String text)

  Escapes a given string for use in a java.util.regex pattern.

  Since:
    jEdit 4.5pre1

### indexIgnoringWhitespace

    public static void indexIgnoringWhitespace(java.lang.String text,
                                               int maxLineLength,
                                               int tabSize,
                                               java.lang.StringBuffer buf)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD