Class CharSequenceUtils
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
ConstructorsConstructorDescriptionCharSequenceUtilsinstances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleancheckLaterThan1(CharSequence cs, CharSequence searchChar, int len2, int start1) (package private) static intindexOf(CharSequence cs, int searchChar, int start) Returns the index withincsof the first occurrence of the specified character, starting the search at the specified index.(package private) static intindexOf(CharSequence cs, CharSequence searchChar, int start) Used by the indexOf(CharSequence methods) as a green implementation of indexOf.(package private) static intlastIndexOf(CharSequence cs, int searchChar, int start) Returns the index withincsof the last occurrence of the specified character, searching backward starting at the specified index.(package private) static intlastIndexOf(CharSequence cs, CharSequence searchChar, int start) Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf(package private) static booleanregionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length) Green implementation of regionMatches.static CharSequencesubSequence(CharSequence cs, int start) Returns a newCharSequencethat is a subsequence of this sequence starting with thecharvalue 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()CharSequenceUtilsinstances should NOT be constructed in standard programming.This constructor is public to permit tools that require a JavaBean instance to operate.
-
-
Method Details
-
checkLaterThan1
private static boolean checkLaterThan1(CharSequence cs, CharSequence searchChar, int len2, int start1) -
indexOf
Used by the indexOf(CharSequence methods) as a green implementation of indexOf.- Parameters:
cs- theCharSequenceto be processedsearchChar- theCharSequenceto be searched forstart- the start index- Returns:
- the index where the search sequence was found
-
indexOf
Returns the index withincsof the first occurrence of the specified character, starting the search at the specified index.If a character with value
searchCharoccurs in the character sequence represented by thecsobject at an index no smaller thanstart, then the index of the first such occurrence is returned. For values ofsearchCharin 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:(this.codePointAt(k) == searchChar) && (k >= start)
is true. In either case, if no such character occurs inm
csat or after positionstart, then-1is 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 entireCharSequencemay be searched. If it is greater than the length ofcs, it has the same effect as if it were equal to the length ofcs:-1is returned.All indices are specified in
charvalues (Unicode code units).- Parameters:
cs- theCharSequenceto 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
-
lastIndexOf
Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf- Parameters:
cs- theCharSequenceto be processedsearchChar- theCharSequenceto findstart- the start index- Returns:
- the index where the search sequence was found
-
lastIndexOf
Returns the index withincsof the last occurrence of the specified character, searching backward starting at the specified index. For values ofsearchCharin 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)
csat or before positionstart, then-1is returned.All indices are specified in
charvalues (Unicode code units).- Parameters:
cs- theCharSequenceto 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
-
regionMatches
static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length) Green implementation of regionMatches.- Parameters:
cs- theCharSequenceto be processedignoreCase- whether or not to be case-insensitivethisStart- the index to start on thecsCharSequencesubstring- theCharSequenceto be looked forstart- the index to start on thesubstringCharSequencelength- character length of the region- Returns:
- whether the region matched
-
subSequence
Returns a newCharSequencethat is a subsequence of this sequence starting with thecharvalue at the specified index.This provides the
CharSequenceequivalent toString.substring(int). The length (inchar) of the returned sequence islength() - start, so ifstart == endthen 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- ifstartis negative or ifstartis greater thanlength()
-
toCharArray
Converts the given CharSequence to a char[].- Parameters:
source- theCharSequenceto be processed.- Returns:
- the resulting char array, never null.
- Since:
- 3.11
-