java.lang.Object
org.gjt.sp.jedit.TextUtilities
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
- Version:
- $Id: TextUtilities.java 25308 2020-05-03 22:08:41Z kpouer $
- Author:
- Slava Pestov
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
escapeText
(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
(CharSequence line, int pos, String noWordSep) Locates the end of the word at the specified position.static int
findWordEnd
(CharSequence line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace) Locates the end of the word at the specified position.static int
findWordEnd
(String line, int pos, String noWordSep) Locates the end of the word at the specified position.static int
findWordEnd
(String line, int pos, String noWordSep, boolean joinNonWordChars) Locates the end of the word at the specified position.static int
findWordEnd
(String line, int pos, String noWordSep, boolean joinNonWordChars, boolean eatWhitespace) Locates the end of the word at the specified position.static int
findWordEnd
(String line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace) Locates the end of the word at the specified position.static int
findWordStart
(CharSequence line, int pos, String noWordSep) Locates the start of the word at the specified position.static int
findWordStart
(CharSequence line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace) Locates the start of the word at the specified position.static int
findWordStart
(CharSequence line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace, boolean eatOnlyAfterWord) Locates the start 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 noWordSep, boolean joinNonWordChars, boolean eatWhitespace) Locates the start of the word at the specified position.static int
findWordStart
(String line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace) Locates the start of the word at the specified position.static String
Formats the specified text by merging and breaking lines to the specified width.static int
getCharType
(char ch, 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 indirection[0]
.static int
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
(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
(String str, int index) Inverse ofindexIgnoringWhitespace()
.static int
indexIgnoringWhitespace
(String str, int index) Inverse ofignoringWhitespaceIndex()
.static void
indexIgnoringWhitespace
(String text, int maxLineLength, int tabSize, StringBuffer buf) static String
join
(Collection<?> c, String delim) Deprecated.static String
spacesToTabs
(String in, int tabSize) Converts consecutive spaces to tabs in the specified string.static String
tabsToSpaces
(String in, int tabSize) Converts tabs to consecutive spaces in the specified string.static String
toTitleCase
(String str) Converts the specified string to title case, by capitalizing the first letter.
-
Field Details
-
BRACKET_MATCH_LIMIT
public static final int BRACKET_MATCH_LIMIT- See Also:
-
WHITESPACE
public static final int WHITESPACE- See Also:
-
WORD_CHAR
public static final int WORD_CHAR- See Also:
-
SYMBOL
public static final int SYMBOL- See Also:
-
MIXED
public static final int MIXED- See Also:
-
LOWER_CASE
public static final int LOWER_CASE- See Also:
-
UPPER_CASE
public static final int UPPER_CASE- See Also:
-
TITLE_CASE
public static final int TITLE_CASE- See Also:
-
-
Constructor Details
-
TextUtilities
public TextUtilities()
-
-
Method Details
-
getTokenAtOffset
Returns the token that contains the specified offset.- Parameters:
tokens
- The token listoffset
- 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 indirection[0]
. Given a closing bracket, return the corresponding opening bracket and store false indirection[0]
. Otherwise, return\0
.- Since:
- jEdit 4.3pre2
-
findMatchingBracket
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 bufferline
- The lineoffset
- The offset within that line- Since:
- jEdit 2.6pre1
-
join
Deprecated.useString.join(CharSequence, CharSequence...)
orString.join(CharSequence, Iterable)
, thos methods are available since Java 8 and are faster in all situationsSimilar to perl's join() method on lists, but works with all collections.- Parameters:
c
- An iterable collection of Objectsdelim
- a string to put between each object- Returns:
- a joined toString() representation of the collection
- Since:
- jedit 4.3pre3
-
findWordStart
Locates the start of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anyway
-
findWordStart
Locates the start of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anyway- Since:
- jEdit 4.3pre15
-
findWordStart
Locates the start of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one word- Since:
- jEdit 4.2pre5
-
findWordStart
public static int findWordStart(String line, int pos, String noWordSep, boolean joinNonWordChars, boolean eatWhitespace) Locates the start of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one wordeatWhitespace
- Include whitespace at start of word- Since:
- jEdit 4.1pre2
-
findWordStart
public static int findWordStart(String line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace) Locates the start of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one wordcamelCasedWords
- Treat "camelCased" parts as wordseatWhitespace
- Include whitespace at start of word- Since:
- jEdit 4.3pre10
-
findWordStart
public static int findWordStart(CharSequence line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace) Locates the start of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one wordcamelCasedWords
- Treat "camelCased" parts as wordseatWhitespace
- Include whitespace at start of word- Since:
- jEdit 4.3pre15
-
findWordStart
public static int findWordStart(CharSequence line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace, boolean eatOnlyAfterWord) Locates the start of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one wordcamelCasedWords
- Treat "camelCased" parts as wordseatWhitespace
- Include whitespace at start of wordeatOnlyAfterWord
- Eat only whitespace after a word, in effect this finds actual word starts even if eating- Since:
- jEdit 4.4pre1
-
findWordEnd
Locates the end of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anyway
-
findWordEnd
Locates the end of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anyway- Since:
- jEdit 4.3pre15
-
findWordEnd
Locates the end of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one word- Since:
- jEdit 4.1pre2
-
findWordEnd
public static int findWordEnd(String line, int pos, String noWordSep, boolean joinNonWordChars, boolean eatWhitespace) Locates the end of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one wordeatWhitespace
- Include whitespace at end of word- Since:
- jEdit 4.2pre5
-
findWordEnd
public static int findWordEnd(String line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace) Locates the end of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one wordcamelCasedWords
- Treat "camelCased" parts as wordseatWhitespace
- Include whitespace at end of word- Since:
- jEdit 4.3pre10
-
findWordEnd
public static int findWordEnd(CharSequence line, int pos, String noWordSep, boolean joinNonWordChars, boolean camelCasedWords, boolean eatWhitespace) Locates the end of the word at the specified position.- Parameters:
line
- The textpos
- The positionnoWordSep
- Characters that are non-alphanumeric, but should be treated as word characters anywayjoinNonWordChars
- Treat consecutive non-alphanumeric characters as one wordcamelCasedWords
- Treat "camelCased" parts as wordseatWhitespace
- Include whitespace at end of word- Since:
- jEdit 4.3pre15
-
getCharType
Returns the type of the char.- Parameters:
ch
- the characternoWordSep
- 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
Converts consecutive spaces to tabs in the specified string.- Parameters:
in
- The stringtabSize
- The tab size
-
tabsToSpaces
Converts tabs to consecutive spaces in the specified string.- Parameters:
in
- The stringtabSize
- The tab size
-
format
Formats the specified text by merging and breaking lines to the specified width.- Parameters:
text
- The textmaxLineLength
- The maximum line lengthtabSize
- The tab size
-
indexIgnoringWhitespace
Inverse ofignoringWhitespaceIndex()
.- 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
Inverse ofindexIgnoringWhitespace()
.- 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
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
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
Converts the specified string to title case, by capitalizing the first letter.- Parameters:
str
- The string- Since:
- jEdit 4.0pre1
-
escapeText
Escapes a given string for use in a java.util.regex pattern.- Since:
- jEdit 4.5pre1
-
indexIgnoringWhitespace
public static void indexIgnoringWhitespace(String text, int maxLineLength, int tabSize, StringBuffer buf)
-
String.join(CharSequence, CharSequence...)
orString.join(CharSequence, Iterable)
, thos methods are available since Java 8 and are faster in all situations