Top Description Fields Constructors Methods
org.apache.commons.lang3

public Class CharSequenceUtils

extends Object
Class Inheritance

Operations on CharSequence that are null safe.
Since
3.0
See Also
CharSequence

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
public
CharSequenceUtils()
Deprecated TODO Make private in 4.0.

CharSequenceUtils instances should NOT be constructed in standard programming.

Method Summary

Modifier and TypeMethod and Description
private static boolean
checkLaterThan1(final CharSequence cs, final CharSequence searchChar, final int len2, final int start1)

pack-priv static int

Returns:

the index where the search sequence was found, or -1 if there is no such occurrence.
indexOf
(final CharSequence
the CharSequence to be processed
cs
,
final CharSequence
the CharSequence to be searched for
searchChar
,
final int
the start index
start
)

Used by the indexOf(CharSequence methods) as a green implementation of indexOf.

pack-priv static int

Returns:

the index where the search char was found, -1 if not found
indexOf
(final CharSequence
the CharSequence to be processed, not null
cs
,
final int
the char to be searched for
searchChar
,
int
the start index, negative starts at the string start
start
)

Returns the index within cs of the first occurrence of the specified character, starting the search at the specified index.

pack-priv static int

Returns:

the index where the search sequence was found
lastIndexOf
(final CharSequence
the CharSequence to be processed
cs
,
final CharSequence
the CharSequence to find
searchChar
,
int
the start index
start
)

Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf

pack-priv static int

Returns:

the index where the search char was found, -1 if not found.
lastIndexOf
(final CharSequence
the CharSequence to be processed.
cs
,
final int
the char to be searched for.
searchChar
,
int
the start index, negative returns -1, beyond length starts at end.
start
)

Returns the index within cs of the last occurrence of the specified character, searching backward starting at the specified index.

pack-priv static boolean

Returns:

whether the region matched
regionMatches
(final CharSequence
the CharSequence to be processed
cs
,
final boolean
whether or not to be case-insensitive
ignoreCase
,
final int
the index to start on the cs CharSequence
thisStart
,
final CharSequence
the CharSequence to be looked for
substring
,
final int
the index to start on the substring CharSequence
start
,
final int
character length of the region
length
)

Green implementation of regionMatches.

public static CharSequence

Returns:

a new subsequence, may be null
subSequence
(final CharSequence
the specified subsequence, null returns null
cs
,
final int
the start index, inclusive, valid
start
)

Returns a new CharSequence that is a subsequence of this sequence starting with the char value at the specified index.

public static char[]

Returns:

the resulting char array, never null.
toCharArray
(final CharSequence
the CharSequence to be processed.
source
)

Converts the given CharSequence to a char[].

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NOT_FOUNDback to summary
private static final int NOT_FOUND
TO_STRING_LIMITback to summary
pack-priv static final int TO_STRING_LIMIT

Constructor Detail

CharSequenceUtilsback to summary
public CharSequenceUtils()

Deprecated

TODO Make private in 4.0.

CharSequenceUtils instances should NOT be constructed in standard programming.

This constructor is public to permit tools that require a JavaBean instance to operate.

Annotations
@Deprecated

Method Detail

checkLaterThan1back to summary
private static boolean checkLaterThan1(final CharSequence cs, final CharSequence searchChar, final int len2, final int start1)
indexOfback to summary
pack-priv static int indexOf(final CharSequence cs, final CharSequence searchChar, final int start)

Used by the indexOf(CharSequence methods) as a green implementation of indexOf.

Parameters
cs:CharSequence

the CharSequence to be processed

searchChar:CharSequence

the CharSequence to be searched for

start:int

the start index

Returns:int

the index where the search sequence was found, or -1 if there is no such occurrence.

indexOfback to summary
pack-priv static int indexOf(final CharSequence cs, final int searchChar, int start)

Returns the index within cs 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 the cs object at an index no smaller than start, then the index of the first such occurrence is returned. For values of searchChar in 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 cs at or after position start, 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 entire CharSequence may be searched. If it is greater than the length of cs, it has the same effect as if it were equal to the length of cs: -1 is returned.

All indices are specified in char values (Unicode code units).

Parameters
cs:CharSequence

the CharSequence to be processed, not null

searchChar:int

the char to be searched for

start:int

the start index, negative starts at the string start

Returns:int

the index where the search char was found, -1 if not found

Since
3.6 updated to behave more like String
lastIndexOfback to summary
pack-priv static int lastIndexOf(final CharSequence cs, final CharSequence searchChar, int start)

Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf

Parameters
cs:CharSequence

the CharSequence to be processed

searchChar:CharSequence

the CharSequence to find

start:int

the start index

Returns:int

the index where the search sequence was found

lastIndexOfback to summary
pack-priv static int lastIndexOf(final CharSequence cs, final int searchChar, int start)

Returns the index within cs of the last occurrence of the specified character, searching backward starting at the specified index. For values of searchChar in 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 cs at or before position start, then -1 is returned.

All indices are specified in char values (Unicode code units).

Parameters
cs:CharSequence

the CharSequence to be processed.

searchChar:int

the char to be searched for.

start:int

the start index, negative returns -1, beyond length starts at end.

Returns:int

the index where the search char was found, -1 if not found.

Since
3.6 updated to behave more like String
regionMatchesback to summary
pack-priv static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart, final CharSequence substring, final int start, final int length)

Green implementation of regionMatches.

Parameters
cs:CharSequence

the CharSequence to be processed

ignoreCase:boolean

whether or not to be case-insensitive

thisStart:int

the index to start on the cs CharSequence

substring:CharSequence

the CharSequence to be looked for

start:int

the index to start on the substring CharSequence

length:int

character length of the region

Returns:boolean

whether the region matched

See Also
String#regionMatches(boolean, int, String, int, int)
subSequenceback to summary
public static CharSequence subSequence(final CharSequence cs, final int start)

Returns a new CharSequence that is a subsequence of this sequence starting with the char value at the specified index.

This provides the CharSequence equivalent to String#substring(int). The length (in char) of the returned sequence is length() - start, so if start == end then an empty sequence is returned.

Parameters
cs:CharSequence

the specified subsequence, null returns null

start:int

the start index, inclusive, valid

Returns:CharSequence

a new subsequence, may be null

Exceptions
IndexOutOfBoundsException:
if start is negative or if start is greater than length()
toCharArrayback to summary
public static char[] toCharArray(final CharSequence source)

Converts the given CharSequence to a char[].

Parameters
source:CharSequence

the CharSequence to be processed.

Returns:char[]

the resulting char array, never null.

Since
3.11