Package com.jogamp.common.util
Class StringUtil
- java.lang.Object
-
- com.jogamp.common.util.StringUtil
-
public class StringUtil extends Object
Basic utility functions forStringandCharSequencein general.
-
-
Field Summary
Fields Modifier and Type Field Description static charCRCR character unicode'\r', 0x000D.static charLFLinefeed character unicode'\n', 0x000A.static charSPACESpace character unicode' ', 0x0020.static StringWHITESPACEList of ASCII & Unicode space separator, akaWhitespace.
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intgetLineCount(CharSequence s)Returns number of lines, i.e.static booleanhasSpace(int cp)static intindexOf(CharSequence hay, int needle, int start)Naive implementation ofString.indexOf(int, int)for typeCharSequence.static intindexOf(String hay, int needle, int start)CallsString.indexOf(int, int)static booleanisFullwidth(int cp)Returns true if given codepoint is a fullwidth unicode character.static booleanisHalfwidth(int cp)Returns true if given codepoint is a halfwidth unicode character.static booleanisWhitespace(int cp)Return true if given codepoint in included withinWHITESPACE.static List<String>split(String text, int lineCount, String separators)static Stringsplit(String text, int lineCount, String separators, String lineSeparator)Returns a multi-line string of splittextatseparatorsorwhitespaceglued with givenlineSeparator.static Stringtrim(String text, String separators, String replacement)Remove all leading, trailing and duplicate-withinseparatorsunicode character from thetext.
-
-
-
Field Detail
-
LF
public static final char LF
Linefeed character unicode'\n', 0x000A.- See Also:
- Constant Field Values
-
CR
public static final char CR
CR character unicode'\r', 0x000D.- See Also:
- Constant Field Values
-
SPACE
public static final char SPACE
Space character unicode' ', 0x0020.- See Also:
- Constant Field Values
-
WHITESPACE
public static final String WHITESPACE
List of ASCII & Unicode space separator, akaWhitespace.
-
-
Method Detail
-
isWhitespace
public static boolean isWhitespace(int cp)
Return true if given codepoint in included withinWHITESPACE.
-
isFullwidth
public static boolean isFullwidth(int cp)
Returns true if given codepoint is a fullwidth unicode character.
-
isHalfwidth
public static boolean isHalfwidth(int cp)
Returns true if given codepoint is a halfwidth unicode character.
-
hasSpace
public static boolean hasSpace(int cp)
-
getLineCount
public static int getLineCount(CharSequence s)
Returns number of lines, i.e. number of non-empty lines, separated byLF.
-
indexOf
public static int indexOf(String hay, int needle, int start)
CallsString.indexOf(int, int)- Parameters:
hay- the unicode character string to search in fromfromIdxneedle- the unicode code point character to searchstart- index to start searching- Returns:
-1if not found, otherwise [0..String.length()-1].- See Also:
indexOf(CharSequence, int, int),String.indexOf(int, int)
-
indexOf
public static int indexOf(CharSequence hay, int needle, int start)
Naive implementation ofString.indexOf(int, int)for typeCharSequence.Uses
String.indexOf(int, int)ifhayis of typeString, otherwise- Parameters:
hay- the unicode character string to search in fromfromIdxneedle- the unicode code point character to searchstart- index to start searching- Returns:
-1if not found, otherwise [0..String.length()-1].- See Also:
#indexOf(String, char, int),String.indexOf(int, int)
-
trim
public static String trim(String text, String separators, String replacement)
Remove all leading, trailing and duplicate-withinseparatorsunicode character from thetext.Duplicate
separatorsunicode character within thetextare reduced to one occurrence and might be replaced withreplacementif notnull.- Parameters:
text- the source textseparators- separator unicode characters, passnullforwhitespace. Consider usingWHITESPACEto cover all unicode space character.replacement- optional replacement string for matched separator within sequence removing duplicated. Ifnull, the first found separator is used.- Returns:
- stripped text
-
split
public static List<String> split(String text, int lineCount, String separators)
Returns an array of splittextatseparatorsorwhitespace.Each line's cutting point is the first
separatororwhitespaceoccurrence starting attext.length() / lineCount * 0.9.The separator or
whitespacecharacter at the cutting point is skipped in the resulting array of the split parts, i.e. lines.- Parameters:
text- the text to be split,nullresults in an empty listlineCount- number of resulting linesseparators- separator unicode characters, passnullforwhitespace. Consider usingWHITESPACEto cover all unicode space character.- See Also:
split(String, int, String, String)
-
split
public static String split(String text, int lineCount, String separators, String lineSeparator)
Returns a multi-line string of splittextatseparatorsorwhitespaceglued with givenlineSeparator.Each line's cutting point is the first
separatororwhitespaceoccurrence starting attext.length() / lineCount * 0.9.The separator character or
whitespaceat the cutting point is skipped in the string of glued split parts, i.e. lines.- Parameters:
text- the text to be split,nullresults in an empty listlineCount- number of resulting linesseparators- separator unicode characters, passnullforwhitespace. Consider usingWHITESPACEto cover all unicode space character.lineSeparator- the glue placed between the split lines in the concatenated result- See Also:
split(String, int, String)
-
-