Class CharSequenceUtils
- java.lang.Object
-
- org.apache.commons.lang3.CharSequenceUtils
-
public class CharSequenceUtils extends Object
Operations on
CharSequencethat arenullsafe.- Since:
- 3.0
- See Also:
CharSequence
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intTO_STRING_LIMIT
-
Constructor Summary
Constructors Constructor Description CharSequenceUtils()CharSequenceUtilsinstances should NOT be constructed in standard programming.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (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 Detail
-
TO_STRING_LIMIT
static final int TO_STRING_LIMIT
- See Also:
- Constant Field Values
-
-
Method Detail
-
subSequence
public static CharSequence subSequence(CharSequence cs, int start)
Returns a new
CharSequencethat 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()
-
indexOf
static int indexOf(CharSequence cs, int searchChar, int start)
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:
is true. In either case, if no such character occurs inm(this.codePointAt(k) == searchChar) && (k >= start)
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
-
indexOf
static int indexOf(CharSequence cs, CharSequence searchChar, int start)
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
-
lastIndexOf
static int lastIndexOf(CharSequence cs, int searchChar, int start)
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
-
lastIndexOf
static int lastIndexOf(CharSequence cs, CharSequence searchChar, int start)
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
-
toCharArray
public static char[] toCharArray(CharSequence source)
Converts the given CharSequence to a char[].- Parameters:
source- theCharSequenceto 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- 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
-
-