Class CharSequenceUtils
Operations on CharSequence
that are
null
safe.
- Since:
- 3.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
(package private) static final int
-
Constructor Summary
ConstructorsConstructorDescriptionCharSequenceUtils
instances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
checkLaterThan1
(CharSequence cs, CharSequence searchChar, int len2, int start1) (package private) static int
indexOf
(CharSequence cs, int searchChar, int start) Returns the index withincs
of the first occurrence of the specified character, starting the search at the specified index.(package private) static int
indexOf
(CharSequence cs, CharSequence searchChar, int start) Used by the indexOf(CharSequence methods) as a green implementation of indexOf.(package private) static int
lastIndexOf
(CharSequence cs, int searchChar, int start) Returns the index withincs
of the last occurrence of the specified character, searching backward starting at the specified index.(package private) static int
lastIndexOf
(CharSequence cs, CharSequence searchChar, int start) Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf(package private) static boolean
regionMatches
(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length) Green implementation of regionMatches.static CharSequence
subSequence
(CharSequence cs, int start) Returns a newCharSequence
that is a subsequence of this sequence starting with thechar
value at the specified index.static char[]
toCharArray
(CharSequence source) Converts the given CharSequence to a char[].
-
Field Details
-
NOT_FOUND
private static final int NOT_FOUND- See Also:
-
TO_STRING_LIMIT
static final int TO_STRING_LIMIT- See Also:
-
-
Constructor Details
-
CharSequenceUtils
public CharSequenceUtils()CharSequenceUtils
instances should NOT be constructed in standard programming.This constructor is public to permit tools that require a JavaBean instance to operate.
-
-
Method Details
-
subSequence
Returns a new
CharSequence
that is a subsequence of this sequence starting with thechar
value at the specified index.This provides the
CharSequence
equivalent toString.substring(int)
. The length (inchar
) of the returned sequence islength() - start
, so ifstart == end
then an empty sequence is returned.- Parameters:
cs
- the specified subsequence, null returns nullstart
- the start index, inclusive, valid- Returns:
- a new subsequence, may be null
- Throws:
IndexOutOfBoundsException
- ifstart
is negative or ifstart
is greater thanlength()
-
indexOf
Returns the index withincs
of the first occurrence of the specified character, starting the search at the specified index.If a character with value
searchChar
occurs in the character sequence represented by thecs
object at an index no smaller thanstart
, then the index of the first such occurrence is returned. For values ofsearchChar
in the range from 0 to 0xFFFF (inclusive), this is the smallest value k such that:
is true. For other values of(this.charAt(k) == searchChar) && (k >= start)
searchChar
, it is the smallest value k such that:
is true. In either case, if no such character occurs inm(this.codePointAt(k) == searchChar) && (k >= start)
cs
at or after positionstart
, then-1
is returned.There is no restriction on the value of
start
. If it is negative, it has the same effect as if it were zero: the entireCharSequence
may be searched. If it is greater than the length ofcs
, it has the same effect as if it were equal to the length ofcs
:-1
is returned.All indices are specified in
char
values (Unicode code units).- Parameters:
cs
- theCharSequence
to be processed, not nullsearchChar
- the char to be searched forstart
- the start index, negative starts at the string start- Returns:
- the index where the search char was found, -1 if not found
- Since:
- 3.6 updated to behave more like
String
-
indexOf
Used by the indexOf(CharSequence methods) as a green implementation of indexOf.- Parameters:
cs
- theCharSequence
to be processedsearchChar
- theCharSequence
to be searched forstart
- the start index- Returns:
- the index where the search sequence was found
-
lastIndexOf
Returns the index withincs
of the last occurrence of the specified character, searching backward starting at the specified index. For values ofsearchChar
in the range from 0 to 0xFFFF (inclusive), the index returned is the largest value k such that:
is true. For other values of(this.charAt(k) == searchChar) && (k <= start)
searchChar
, it is the largest value k such that:
is true. In either case, if no such character occurs in(this.codePointAt(k) == searchChar) && (k <= start)
cs
at or before positionstart
, then-1
is returned.All indices are specified in
char
values (Unicode code units).- Parameters:
cs
- theCharSequence
to be processedsearchChar
- the char to be searched forstart
- the start index, negative returns -1, beyond length starts at end- Returns:
- the index where the search char was found, -1 if not found
- Since:
- 3.6 updated to behave more like
String
-
lastIndexOf
Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf- Parameters:
cs
- theCharSequence
to be processedsearchChar
- theCharSequence
to findstart
- the start index- Returns:
- the index where the search sequence was found
-
checkLaterThan1
private static boolean checkLaterThan1(CharSequence cs, CharSequence searchChar, int len2, int start1) -
toCharArray
Converts the given CharSequence to a char[].- Parameters:
source
- theCharSequence
to be processed.- Returns:
- the resulting char array, never null.
- Since:
- 3.11
-
regionMatches
static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length) Green implementation of regionMatches.- Parameters:
cs
- theCharSequence
to be processedignoreCase
- whether or not to be case insensitivethisStart
- the index to start on thecs
CharSequencesubstring
- theCharSequence
to be looked forstart
- the index to start on thesubstring
CharSequencelength
- character length of the region- Returns:
- whether the region matched
-