Package com.jogamp.common.util
Class StringUtil
- java.lang.Object
-
- com.jogamp.common.util.StringUtil
-
public class StringUtil extends Object
Basic utility functions forString
andCharSequence
in general.
-
-
Field Summary
Fields Modifier and Type Field Description static char
CR
CR character unicode'\r'
, 0x000D.static char
LF
Linefeed character unicode'\n'
, 0x000A.static char
SPACE
Space character unicode' '
, 0x0020.static String
WHITESPACE
List 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 int
getLineCount(CharSequence s)
Returns number of lines, i.e.static boolean
hasSpace(int cp)
static int
indexOf(CharSequence hay, int needle, int start)
Naive implementation ofString.indexOf(int, int)
for typeCharSequence
.static int
indexOf(String hay, int needle, int start)
CallsString.indexOf(int, int)
static boolean
isFullwidth(int cp)
Returns true if given codepoint is a fullwidth unicode character.static boolean
isHalfwidth(int cp)
Returns true if given codepoint is a halfwidth unicode character.static boolean
isWhitespace(int cp)
Return true if given codepoint in included withinWHITESPACE
.static List<String>
split(String text, int lineCount, String separators)
static String
split(String text, int lineCount, String separators, String lineSeparator)
Returns a multi-line string of splittext
atseparators
orwhitespace
glued with givenlineSeparator
.static String
trim(String text, String separators, String replacement)
Remove all leading, trailing and duplicate-withinseparators
unicode 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 fromfromIdx
needle
- the unicode code point character to searchstart
- index to start searching- Returns:
-1
if 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)
ifhay
is of typeString
, otherwise- Parameters:
hay
- the unicode character string to search in fromfromIdx
needle
- the unicode code point character to searchstart
- index to start searching- Returns:
-1
if 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-withinseparators
unicode character from thetext
.Duplicate
separators
unicode character within thetext
are reduced to one occurrence and might be replaced withreplacement
if notnull
.- Parameters:
text
- the source textseparators
- separator unicode characters, passnull
forwhitespace
. Consider usingWHITESPACE
to 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 splittext
atseparators
orwhitespace
.Each line's cutting point is the first
separator
orwhitespace
occurrence starting attext.length() / lineCount * 0.9
.The separator or
whitespace
character at the cutting point is skipped in the resulting array of the split parts, i.e. lines.- Parameters:
text
- the text to be split,null
results in an empty listlineCount
- number of resulting linesseparators
- separator unicode characters, passnull
forwhitespace
. Consider usingWHITESPACE
to 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 splittext
atseparators
orwhitespace
glued with givenlineSeparator
.Each line's cutting point is the first
separator
orwhitespace
occurrence starting attext.length() / lineCount * 0.9
.The separator character or
whitespace
at the cutting point is skipped in the string of glued split parts, i.e. lines.- Parameters:
text
- the text to be split,null
results in an empty listlineCount
- number of resulting linesseparators
- separator unicode characters, passnull
forwhitespace
. Consider usingWHITESPACE
to cover all unicode space character.lineSeparator
- the glue placed between the split lines in the concatenated result- See Also:
split(String, int, String)
-
-