Class CharSequenceUtils
CharSequence that are
null safe.- Since:
- 3.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final booleanWhether the running JDK folds a supplementary code point split across a surrogate pair when comparing case insensitively inString.regionMatches(boolean, int, String, int, int).(package private) static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleancheckLaterThan1(CharSequence cs, CharSequence searchChar, int len2, int start1) private static booleanequalsIgnoreCase(int cp1, int cp2) Tests whether two code points are equal ignoring case, matching the folding used byString.regionMatches(boolean, int, String, int, int).(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) Tests if two string regions are equal.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:
-
STRING_FOLDS_SUPPLEMENTARY_CASE
private static final boolean STRING_FOLDS_SUPPLEMENTARY_CASEWhether the running JDK folds a supplementary code point split across a surrogate pair when comparing case insensitively inString.regionMatches(boolean, int, String, int, int). JDKs up to and including Java 11 compare surrogate by surrogate and never match such a pair; later JDKs fold the whole code point. Probing whatStringactually does (rather than gating on a version constant) keeps everyCharSequencetype in step withStringon whatever JDK is running. DESERET CAPITAL LETTER LONG I (U+10400) folds to its small form (U+10428). -
TO_STRING_LIMIT
static final int TO_STRING_LIMIT- See Also:
-
-
Constructor Details
-
CharSequenceUtils
Deprecated.TODO Make private in 4.0.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) -
equalsIgnoreCase
private static boolean equalsIgnoreCase(int cp1, int cp2) Tests whether two code points are equal ignoring case, matching the folding used byString.regionMatches(boolean, int, String, int, int).- Parameters:
cp1- The first code point.cp2- The second code point.- Returns:
- whether the code points are equal ignoring case.
-
indexOf
Used by the indexOf(CharSequence methods) as a green implementation of indexOf.CharSequencetypes without a dedicated branch are scanned in place rather than materialized withtoString(): for builder types (for exampleorg.apache.commons.lang3.text.StrBuilder),toString()copies the whole buffer, and callers that invoke this method once per occurrence (such asdeleteAll/replaceAll) would multiply that copy into allocation-quadratic churn.- Parameters:
cs- TheCharSequenceto be processed.searchChar- TheCharSequenceto be searched for.start- The start index.- Returns:
- The index where the search sequence was found, or
-1if there is no such occurrence.
-
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:(this.charAt(k) == searchChar) && (k >= start)
is true. For other values of
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 null.searchChar- The char to be searched for.start- 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 processed.searchChar- TheCharSequenceto find.start- 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:(this.charAt(k) == searchChar) && (k <= start)
is true. For other values of
searchChar, it is the largest value k such that:(this.codePointAt(k) == searchChar) && (k <= start)
is true. In either case, if no such character occurs in
csat or before positionstart, then-1is returned.All indices are specified in
charvalues (Unicode code units).- Parameters:
cs- TheCharSequenceto be processed.searchChar- The char to be searched for.start- 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) Tests if two string regions are equal.- Parameters:
cs- TheCharSequenceto be processed.ignoreCase- whether or not to be case-insensitive.thisStart- The index to start on thecsCharSequence.substring- TheCharSequenceto be looked for.start- The index to start on thesubstringCharSequence.length- character length of the region.- Returns:
- whether the region matched.
- See Also:
-
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 null.start- The start index, inclusive, valid.- Returns:
- A new subsequence, may be null.
- Throws:
IndexOutOfBoundsException- Thrown 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
-