Package android.text
Class TextUtils
- java.lang.Object
-
- android.text.TextUtils
-
public class TextUtils extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTextUtils.EllipsizeCallbackstatic classTextUtils.SimpleStringSplitterA simple string splitter.static interfaceTextUtils.StringSplitterAn interface for splitting strings according to rules that are opaque to the user of this interface.static classTextUtils.TruncateAt
-
Field Summary
Fields Modifier and Type Field Description static intABSOLUTE_SIZE_SPANstatic intACCESSIBILITY_CLICKABLE_SPANstatic intACCESSIBILITY_URL_SPANstatic intALIGNMENT_SPANstatic intANNOTATIONstatic intBACKGROUND_COLOR_SPANstatic intBULLET_SPANstatic intCAP_MODE_CHARACTERSCapitalization mode forgetCapsMode(java.lang.CharSequence, int, int): capitalize all characters.static intCAP_MODE_SENTENCESCapitalization mode forgetCapsMode(java.lang.CharSequence, int, int): capitalize the first character of each sentence.static intCAP_MODE_WORDSCapitalization mode forgetCapsMode(java.lang.CharSequence, int, int): capitalize the first character of all words.static Parcelable.Creator<java.lang.CharSequence>CHAR_SEQUENCE_CREATORstatic intEASY_EDIT_SPANstatic intFIRST_SPANstatic intFOREGROUND_COLOR_SPANstatic intLAST_SPANstatic intLEADING_MARGIN_SPANstatic intLOCALE_SPANstatic intQUOTE_SPANstatic intRELATIVE_SIZE_SPANstatic intSCALE_X_SPANstatic intSPELL_CHECK_SPANstatic intSTRIKETHROUGH_SPANstatic intSTYLE_SPANstatic intSUBSCRIPT_SPANstatic intSUGGESTION_RANGE_SPANstatic intSUGGESTION_SPANstatic intSUPERSCRIPT_SPANstatic intTEXT_APPEARANCE_SPANstatic intTTS_SPANstatic intTYPEFACE_SPANstatic intUNDERLINE_SPANstatic intURL_SPAN
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.CharSequencecommaEllipsize(java.lang.CharSequence text, android.text.TextPaint p, float avail, java.lang.String oneMore, java.lang.String more)Deprecated.Do not use.static java.lang.CharSequencecommaEllipsize(java.lang.CharSequence text, android.text.TextPaint p, float avail, java.lang.String oneMore, java.lang.String more, android.text.TextDirectionHeuristic textDir)Deprecated.static java.lang.CharSequenceconcat(java.lang.CharSequence... text)Returns a CharSequence concatenating the specified CharSequences, retaining their spans if any.static voidcopySpansFrom(Spanned source, int start, int end, java.lang.Class kind, Spannable dest, int destoff)Copies the spans from the regionstart...endinsourceto the regiondestoff...destoff+end-startindest.static booleandelimitedStringContains(java.lang.String delimitedString, char delimiter, java.lang.String item)Does a comma-delimited list 'delimitedString' contain a certain item? (without allocating memory)static voiddumpSpans(java.lang.CharSequence cs, android.util.Printer printer, java.lang.String prefix)Debugging tool to print the spans in a CharSequence.static java.lang.CharSequenceellipsize(java.lang.CharSequence text, android.text.TextPaint p, float avail, TextUtils.TruncateAt where)Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a truncated copy with ellipsis character added at the specified edge or center.static java.lang.CharSequenceellipsize(java.lang.CharSequence text, android.text.TextPaint paint, float avail, TextUtils.TruncateAt where, boolean preserveLength, TextUtils.EllipsizeCallback callback)Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a copy with ellipsis character added at the specified edge or center.static java.lang.CharSequenceellipsize(java.lang.CharSequence text, android.text.TextPaint paint, float avail, TextUtils.TruncateAt where, boolean preserveLength, TextUtils.EllipsizeCallback callback, android.text.TextDirectionHeuristic textDir, java.lang.String ellipsis)Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a copy with ellipsis character added at the specified edge or center.static java.lang.StringemptyIfNull(java.lang.String str){}static booleanequals(java.lang.CharSequence a, java.lang.CharSequence b)Returns true if a and b are equal, including if they are both null.static java.lang.CharSequenceexpandTemplate(java.lang.CharSequence template, java.lang.CharSequence... values)Replace instances of "^1", "^2", etc.static java.lang.StringfirstNotEmpty(java.lang.String a, java.lang.String b){}static intgetCapsMode(java.lang.CharSequence cs, int off, int reqModes)Determine what caps mode should be in effect at the current offset in the text.static voidgetChars(java.lang.CharSequence s, int start, int end, char[] dest, int destoff)static java.lang.StringgetEllipsisString(TextUtils.TruncateAt method){}static intgetOffsetAfter(java.lang.CharSequence text, int offset)static intgetOffsetBefore(java.lang.CharSequence text, int offset)static java.lang.CharSequencegetReverse(java.lang.CharSequence source, int start, int end)Deprecated.Do not use.static intgetTrimmedLength(java.lang.CharSequence s)Returns the length that the specified CharSequence would have if spaces and ASCII control characters were trimmed from the start and end, as byString.trim().static booleanhasStyleSpan(Spanned spanned)Returns whether or not the specified spanned text has a style span.static java.lang.StringhtmlEncode(java.lang.String s)Html-encode the string.static intindexOf(java.lang.CharSequence s, char ch)static intindexOf(java.lang.CharSequence s, char ch, int start)static intindexOf(java.lang.CharSequence s, char ch, int start, int end)static intindexOf(java.lang.CharSequence s, java.lang.CharSequence needle)static intindexOf(java.lang.CharSequence s, java.lang.CharSequence needle, int start)static intindexOf(java.lang.CharSequence s, java.lang.CharSequence needle, int start, int end)static booleanisDigitsOnly(java.lang.CharSequence str)Returns whether the given CharSequence contains only digits.static booleanisEmpty(java.lang.CharSequence str)Returns true if the string is null or 0-length.static booleanisGraphic(char c)Deprecated.UseisGraphic(CharSequence)instead.static booleanisGraphic(java.lang.CharSequence str)Returns whether the given CharSequence contains any printable characters.static booleanisPrintableAscii(char c)static booleanisPrintableAsciiOnly(java.lang.CharSequence str)static java.lang.Stringjoin(java.lang.CharSequence delimiter, java.lang.Iterable tokens)Returns a string containing the tokens joined by delimiters.static java.lang.Stringjoin(java.lang.CharSequence delimiter, java.lang.Object[] tokens)Returns a string containing the tokens joined by delimiters.static intlastIndexOf(java.lang.CharSequence s, char ch)static intlastIndexOf(java.lang.CharSequence s, char ch, int last)static intlastIndexOf(java.lang.CharSequence s, char ch, int start, int last)static intlength(java.lang.String s){}static java.lang.StringnullIfEmpty(java.lang.String str){}static longpackRangeInLong(int start, int end)Pack 2 int values into a long, useful as a return value for a rangestatic booleanregionMatches(java.lang.CharSequence one, int toffset, java.lang.CharSequence two, int ooffset, int len)static <T> T[]removeEmptySpans(T[] spans, Spanned spanned, java.lang.Class<T> klass)Removes empty spans from thespansarray.static java.lang.CharSequencereplace(java.lang.CharSequence template, java.lang.String[] sources, java.lang.CharSequence[] destinations)Return a new CharSequence in which each of the source strings is replaced by the corresponding element of the destinations.static java.lang.StringsafeIntern(java.lang.String s)static java.lang.String[]split(java.lang.String text, java.lang.String expression)String.split() returns [''] when the string to be split is empty.static java.lang.String[]split(java.lang.String text, java.util.regex.Pattern pattern)Splits a string on a pattern.static java.lang.CharSequencestringOrSpannedString(java.lang.CharSequence source)static java.lang.Stringsubstring(java.lang.CharSequence source, int start, int end)Create a new String object containing the given range of characters from the source string.static java.lang.CharSequencetoUpperCase(java.util.Locale locale, java.lang.CharSequence source, boolean copySpans)Transforms a CharSequences to uppercase, copying the sources spans and keeping them spans as much as possible close to their relative original places.static java.lang.CharSequencetrimNoCopySpans(java.lang.CharSequence charSequence)If thecharSequenceis instance ofSpanned, creates a new copy andNoCopySpan's are removed from the copy.static <T extends java.lang.CharSequence>
TtrimToParcelableSize(T text)Trims the text toPARCEL_SAFE_TEXT_LENGTHlength.static <T extends java.lang.CharSequence>
TtrimToSize(T text, int size)Trims the text tosizelength.static intunpackRangeEndFromLong(long range)Get the end value from a range packed in a long bypackRangeInLong(int, int)static intunpackRangeStartFromLong(long range)Get the start value from a range packed in a long bypackRangeInLong(int, int)static voidwrap(java.lang.StringBuilder builder, java.lang.String start, java.lang.String end)Prependsstartand appendsendto a givenStringBuilderstatic voidwriteToParcel(java.lang.CharSequence cs, android.os.Parcel p, int parcelableFlags)Flatten a CharSequence and whatever styles can be copied across processes into the parcel.
-
-
-
Field Detail
-
ALIGNMENT_SPAN
public static final int ALIGNMENT_SPAN
- See Also:
- Constant Field Values
-
FIRST_SPAN
public static final int FIRST_SPAN
- See Also:
- Constant Field Values
-
FOREGROUND_COLOR_SPAN
public static final int FOREGROUND_COLOR_SPAN
- See Also:
- Constant Field Values
-
RELATIVE_SIZE_SPAN
public static final int RELATIVE_SIZE_SPAN
- See Also:
- Constant Field Values
-
SCALE_X_SPAN
public static final int SCALE_X_SPAN
- See Also:
- Constant Field Values
-
STRIKETHROUGH_SPAN
public static final int STRIKETHROUGH_SPAN
- See Also:
- Constant Field Values
-
UNDERLINE_SPAN
public static final int UNDERLINE_SPAN
- See Also:
- Constant Field Values
-
STYLE_SPAN
public static final int STYLE_SPAN
- See Also:
- Constant Field Values
-
BULLET_SPAN
public static final int BULLET_SPAN
- See Also:
- Constant Field Values
-
QUOTE_SPAN
public static final int QUOTE_SPAN
- See Also:
- Constant Field Values
-
LEADING_MARGIN_SPAN
public static final int LEADING_MARGIN_SPAN
- See Also:
- Constant Field Values
-
URL_SPAN
public static final int URL_SPAN
- See Also:
- Constant Field Values
-
BACKGROUND_COLOR_SPAN
public static final int BACKGROUND_COLOR_SPAN
- See Also:
- Constant Field Values
-
TYPEFACE_SPAN
public static final int TYPEFACE_SPAN
- See Also:
- Constant Field Values
-
SUPERSCRIPT_SPAN
public static final int SUPERSCRIPT_SPAN
- See Also:
- Constant Field Values
-
SUBSCRIPT_SPAN
public static final int SUBSCRIPT_SPAN
- See Also:
- Constant Field Values
-
ABSOLUTE_SIZE_SPAN
public static final int ABSOLUTE_SIZE_SPAN
- See Also:
- Constant Field Values
-
TEXT_APPEARANCE_SPAN
public static final int TEXT_APPEARANCE_SPAN
- See Also:
- Constant Field Values
-
ANNOTATION
public static final int ANNOTATION
- See Also:
- Constant Field Values
-
SUGGESTION_SPAN
public static final int SUGGESTION_SPAN
- See Also:
- Constant Field Values
-
SPELL_CHECK_SPAN
public static final int SPELL_CHECK_SPAN
- See Also:
- Constant Field Values
-
SUGGESTION_RANGE_SPAN
public static final int SUGGESTION_RANGE_SPAN
- See Also:
- Constant Field Values
-
EASY_EDIT_SPAN
public static final int EASY_EDIT_SPAN
- See Also:
- Constant Field Values
-
LOCALE_SPAN
public static final int LOCALE_SPAN
- See Also:
- Constant Field Values
-
TTS_SPAN
public static final int TTS_SPAN
- See Also:
- Constant Field Values
-
ACCESSIBILITY_CLICKABLE_SPAN
public static final int ACCESSIBILITY_CLICKABLE_SPAN
- See Also:
- Constant Field Values
-
ACCESSIBILITY_URL_SPAN
public static final int ACCESSIBILITY_URL_SPAN
- See Also:
- Constant Field Values
-
LAST_SPAN
public static final int LAST_SPAN
- See Also:
- Constant Field Values
-
CHAR_SEQUENCE_CREATOR
public static final Parcelable.Creator<java.lang.CharSequence> CHAR_SEQUENCE_CREATOR
-
CAP_MODE_CHARACTERS
public static final int CAP_MODE_CHARACTERS
Capitalization mode forgetCapsMode(java.lang.CharSequence, int, int): capitalize all characters. This value is explicitly defined to be the same asInputType.TYPE_TEXT_FLAG_CAP_CHARACTERS.- See Also:
- Constant Field Values
-
CAP_MODE_WORDS
public static final int CAP_MODE_WORDS
Capitalization mode forgetCapsMode(java.lang.CharSequence, int, int): capitalize the first character of all words. This value is explicitly defined to be the same asInputType.TYPE_TEXT_FLAG_CAP_WORDS.- See Also:
- Constant Field Values
-
CAP_MODE_SENTENCES
public static final int CAP_MODE_SENTENCES
Capitalization mode forgetCapsMode(java.lang.CharSequence, int, int): capitalize the first character of each sentence. This value is explicitly defined to be the same asInputType.TYPE_TEXT_FLAG_CAP_SENTENCES.- See Also:
- Constant Field Values
-
-
Method Detail
-
getEllipsisString
public static java.lang.String getEllipsisString(TextUtils.TruncateAt method)
{}
-
getChars
public static void getChars(java.lang.CharSequence s, int start, int end, char[] dest, int destoff)
-
indexOf
public static int indexOf(java.lang.CharSequence s, char ch)
-
indexOf
public static int indexOf(java.lang.CharSequence s, char ch, int start)
-
indexOf
public static int indexOf(java.lang.CharSequence s, char ch, int start, int end)
-
lastIndexOf
public static int lastIndexOf(java.lang.CharSequence s, char ch)
-
lastIndexOf
public static int lastIndexOf(java.lang.CharSequence s, char ch, int last)
-
lastIndexOf
public static int lastIndexOf(java.lang.CharSequence s, char ch, int start, int last)
-
indexOf
public static int indexOf(java.lang.CharSequence s, java.lang.CharSequence needle)
-
indexOf
public static int indexOf(java.lang.CharSequence s, java.lang.CharSequence needle, int start)
-
indexOf
public static int indexOf(java.lang.CharSequence s, java.lang.CharSequence needle, int start, int end)
-
regionMatches
public static boolean regionMatches(java.lang.CharSequence one, int toffset, java.lang.CharSequence two, int ooffset, int len)
-
substring
public static java.lang.String substring(java.lang.CharSequence source, int start, int end)Create a new String object containing the given range of characters from the source string. This is different than simply callingCharSequence.subSequencein that it does not preserve any style runs in the source sequence, allowing a more efficient implementation.
-
join
public static java.lang.String join(java.lang.CharSequence delimiter, java.lang.Object[] tokens)Returns a string containing the tokens joined by delimiters.- Parameters:
delimiter- a CharSequence that will be inserted between the tokens. If null, the string "null" will be used as the delimiter.tokens- an array objects to be joined. Strings will be formed from the objects by calling object.toString(). If tokens is null, a NullPointerException will be thrown. If tokens is an empty array, an empty string will be returned.
-
join
public static java.lang.String join(java.lang.CharSequence delimiter, java.lang.Iterable tokens)Returns a string containing the tokens joined by delimiters.- Parameters:
delimiter- a CharSequence that will be inserted between the tokens. If null, the string "null" will be used as the delimiter.tokens- an array objects to be joined. Strings will be formed from the objects by calling object.toString(). If tokens is null, a NullPointerException will be thrown. If tokens is empty, an empty string will be returned.
-
split
public static java.lang.String[] split(java.lang.String text, java.lang.String expression)String.split() returns [''] when the string to be split is empty. This returns []. This does not remove any empty strings from the result. For example split("a,", "," ) returns {"a", ""}.- Parameters:
text- the string to splitexpression- the regular expression to match- Returns:
- an array of strings. The array will be empty if text is empty
- Throws:
java.lang.NullPointerException- if expression or text is null
-
split
public static java.lang.String[] split(java.lang.String text, java.util.regex.Pattern pattern)Splits a string on a pattern. String.split() returns [''] when the string to be split is empty. This returns []. This does not remove any empty strings from the result.- Parameters:
text- the string to splitpattern- the regular expression to match- Returns:
- an array of strings. The array will be empty if text is empty
- Throws:
java.lang.NullPointerException- if expression or text is null
-
stringOrSpannedString
public static java.lang.CharSequence stringOrSpannedString(java.lang.CharSequence source)
-
isEmpty
public static boolean isEmpty(java.lang.CharSequence str)
Returns true if the string is null or 0-length.- Parameters:
str- the string to be examined- Returns:
- true if str is null or zero length
-
nullIfEmpty
public static java.lang.String nullIfEmpty(java.lang.String str)
{}
-
emptyIfNull
public static java.lang.String emptyIfNull(java.lang.String str)
{}
-
firstNotEmpty
public static java.lang.String firstNotEmpty(java.lang.String a, java.lang.String b){}
-
length
public static int length(java.lang.String s)
{}
-
safeIntern
public static java.lang.String safeIntern(java.lang.String s)
- Returns:
- interned string if it's null.
-
getTrimmedLength
public static int getTrimmedLength(java.lang.CharSequence s)
Returns the length that the specified CharSequence would have if spaces and ASCII control characters were trimmed from the start and end, as byString.trim().
-
equals
public static boolean equals(java.lang.CharSequence a, java.lang.CharSequence b)Returns true if a and b are equal, including if they are both null.Note: In platform versions 1.1 and earlier, this method only worked well if both the arguments were instances of String.
- Parameters:
a- first CharSequence to checkb- second CharSequence to check- Returns:
- true if a and b are equal
-
getReverse
@Deprecated public static java.lang.CharSequence getReverse(java.lang.CharSequence source, int start, int end)Deprecated.Do not use.This function only reverses individualchars and not their associated spans. It doesn't support surrogate pairs (that correspond to non-BMP code points), combining sequences or conjuncts either.
-
writeToParcel
public static void writeToParcel(java.lang.CharSequence cs, android.os.Parcel p, int parcelableFlags)Flatten a CharSequence and whatever styles can be copied across processes into the parcel.
-
dumpSpans
public static void dumpSpans(java.lang.CharSequence cs, android.util.Printer printer, java.lang.String prefix)Debugging tool to print the spans in a CharSequence. The output will be printed one span per line. If the CharSequence is not a Spanned, then the entire string will be printed on a single line.
-
replace
public static java.lang.CharSequence replace(java.lang.CharSequence template, java.lang.String[] sources, java.lang.CharSequence[] destinations)Return a new CharSequence in which each of the source strings is replaced by the corresponding element of the destinations.
-
expandTemplate
public static java.lang.CharSequence expandTemplate(java.lang.CharSequence template, java.lang.CharSequence... values)Replace instances of "^1", "^2", etc. in thetemplateCharSequence with the correspondingvalues. "^^" is used to produce a single caret in the output. Only up to 9 replacement values are supported, "^10" will be produce the first replacement value followed by a '0'.- Parameters:
template- the input text containing "^1"-style placeholder values. This object is not modified; a copy is returned.values- CharSequences substituted into the template. The first is substituted for "^1", the second for "^2", and so on.- Returns:
- the new CharSequence produced by doing the replacement
- Throws:
java.lang.IllegalArgumentException- if the template requests a value that was not provided, or if more than 9 values are provided.
-
getOffsetBefore
public static int getOffsetBefore(java.lang.CharSequence text, int offset)
-
getOffsetAfter
public static int getOffsetAfter(java.lang.CharSequence text, int offset)
-
copySpansFrom
public static void copySpansFrom(Spanned source, int start, int end, java.lang.Class kind, Spannable dest, int destoff)
Copies the spans from the regionstart...endinsourceto the regiondestoff...destoff+end-startindest. Spans insourcethat begin beforestartor end afterendbut overlap this range are trimmed as if they began atstartor ended atend.- Throws:
java.lang.IndexOutOfBoundsException- if any of the copied spans are out of range indest.
-
toUpperCase
public static java.lang.CharSequence toUpperCase(java.util.Locale locale, java.lang.CharSequence source, boolean copySpans)Transforms a CharSequences to uppercase, copying the sources spans and keeping them spans as much as possible close to their relative original places. In the case the the uppercase string is identical to the sources, the source itself is returned instead of being copied. If copySpans is set, source must be an instance of Spanned. {}
-
ellipsize
public static java.lang.CharSequence ellipsize(java.lang.CharSequence text, android.text.TextPaint p, float avail, TextUtils.TruncateAt where)Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a truncated copy with ellipsis character added at the specified edge or center.
-
ellipsize
public static java.lang.CharSequence ellipsize(java.lang.CharSequence text, android.text.TextPaint paint, float avail, TextUtils.TruncateAt where, boolean preserveLength, TextUtils.EllipsizeCallback callback)Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a copy with ellipsis character added at the specified edge or center. IfpreserveLengthis specified, the returned copy will be padded with zero-width spaces to preserve the original length and offsets instead of truncating. Ifcallbackis non-null, it will be called to report the start and end of the ellipsized range. TextDirection is determined by the first strong directional character.
-
ellipsize
public static java.lang.CharSequence ellipsize(java.lang.CharSequence text, android.text.TextPaint paint, float avail, TextUtils.TruncateAt where, boolean preserveLength, TextUtils.EllipsizeCallback callback, android.text.TextDirectionHeuristic textDir, java.lang.String ellipsis)Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a copy with ellipsis character added at the specified edge or center. IfpreserveLengthis specified, the returned copy will be padded with zero-width spaces to preserve the original length and offsets instead of truncating. Ifcallbackis non-null, it will be called to report the start and end of the ellipsized range.
-
commaEllipsize
@Deprecated public static java.lang.CharSequence commaEllipsize(java.lang.CharSequence text, android.text.TextPaint p, float avail, java.lang.String oneMore, java.lang.String more)Deprecated.Do not use. This is not internationalized, and has known issues with right-to-left text, languages that have more than one plural form, languages that use a different character as a comma-like separator, etc. Use listEllipsize instead.Converts a CharSequence of the comma-separated form "Andy, Bob, Charles, David" that is too wide to fit into the specified width into one like "Andy, Bob, 2 more".- Parameters:
text- the text to truncatep- the Paint with which to measure the textavail- the horizontal width available for the text (in pixels)oneMore- the string for "1 more" in the current localemore- the string for "%d more" in the current locale
-
commaEllipsize
@Deprecated public static java.lang.CharSequence commaEllipsize(java.lang.CharSequence text, android.text.TextPaint p, float avail, java.lang.String oneMore, java.lang.String more, android.text.TextDirectionHeuristic textDir)Deprecated.
-
htmlEncode
public static java.lang.String htmlEncode(java.lang.String s)
Html-encode the string.- Parameters:
s- the string to be encoded- Returns:
- the encoded string
-
concat
public static java.lang.CharSequence concat(java.lang.CharSequence... text)
Returns a CharSequence concatenating the specified CharSequences, retaining their spans if any. If there are no parameters, an empty string will be returned. If the number of parameters is exactly one, that parameter is returned as output, even if it is null. If the number of parameters is at least two, any null CharSequence among the parameters is treated as if it was the string"null". If there are paragraph spans in the source CharSequences that satisfy paragraph boundary requirements in the sources but would no longer satisfy them in the concatenated CharSequence, they may get extended in the resulting CharSequence or not retained.
-
isGraphic
public static boolean isGraphic(java.lang.CharSequence str)
Returns whether the given CharSequence contains any printable characters.
-
isGraphic
@Deprecated public static boolean isGraphic(char c)
Deprecated.UseisGraphic(CharSequence)instead.Returns whether this character is a printable character. This does not support non-BMP characters and should not be used.
-
isDigitsOnly
public static boolean isDigitsOnly(java.lang.CharSequence str)
Returns whether the given CharSequence contains only digits.
-
isPrintableAscii
public static boolean isPrintableAscii(char c)
-
isPrintableAsciiOnly
public static boolean isPrintableAsciiOnly(java.lang.CharSequence str)
-
getCapsMode
public static int getCapsMode(java.lang.CharSequence cs, int off, int reqModes)Determine what caps mode should be in effect at the current offset in the text. Only the mode bits set in reqModes will be checked. Note that the caps mode flags here are explicitly defined to match those inInputType.- Parameters:
cs- The text that should be checked for caps modes.off- Location in the text at which to check.reqModes- The modes to be checked: may be any combination ofCAP_MODE_CHARACTERS,CAP_MODE_WORDS, andCAP_MODE_SENTENCES.- Returns:
- Returns the actual capitalization modes that can be in effect
at the current position, which is any combination of
CAP_MODE_CHARACTERS,CAP_MODE_WORDS, andCAP_MODE_SENTENCES.
-
delimitedStringContains
public static boolean delimitedStringContains(java.lang.String delimitedString, char delimiter, java.lang.String item)Does a comma-delimited list 'delimitedString' contain a certain item? (without allocating memory)
-
removeEmptySpans
public static <T> T[] removeEmptySpans(T[] spans, Spanned spanned, java.lang.Class<T> klass)Removes empty spans from thespansarray. When parsing a Spanned usingSpanned.nextSpanTransition(int, int, Class), empty spans will (correctly) create span transitions, and calling getSpans on a slice of text bounded by one of these transitions will (correctly) include the empty overlapping span. However, these empty spans should not be taken into account when layouting or rendering the string and this method provides a way to filter getSpans' results accordingly.- Parameters:
spans- A list of spans retrieved usingSpanned.getSpans(int, int, Class)from thespannedspanned- The Spanned from which spans were extracted- Returns:
- A subset of spans where empty spans (
Spanned.getSpanStart(Object)==Spanned.getSpanEnd(Object)have been removed. The initial order is preserved
-
packRangeInLong
public static long packRangeInLong(int start, int end)Pack 2 int values into a long, useful as a return value for a range
-
unpackRangeStartFromLong
public static int unpackRangeStartFromLong(long range)
Get the start value from a range packed in a long bypackRangeInLong(int, int)
-
unpackRangeEndFromLong
public static int unpackRangeEndFromLong(long range)
Get the end value from a range packed in a long bypackRangeInLong(int, int)
-
hasStyleSpan
public static boolean hasStyleSpan(Spanned spanned)
Returns whether or not the specified spanned text has a style span.
-
trimNoCopySpans
public static java.lang.CharSequence trimNoCopySpans(java.lang.CharSequence charSequence)
If thecharSequenceis instance ofSpanned, creates a new copy andNoCopySpan's are removed from the copy. Otherwise the givencharSequenceis returned as it is.
-
wrap
public static void wrap(java.lang.StringBuilder builder, java.lang.String start, java.lang.String end)Prependsstartand appendsendto a givenStringBuilder
-
trimToParcelableSize
public static <T extends java.lang.CharSequence> T trimToParcelableSize(T text)
Trims the text toPARCEL_SAFE_TEXT_LENGTHlength. Returns the string as it is if the length() is smaller thanPARCEL_SAFE_TEXT_LENGTH. Used for text that is parceled into aParcelable.
-
trimToSize
public static <T extends java.lang.CharSequence> T trimToSize(T text, int size)Trims the text tosizelength. Returns the string as it is if the length() is smaller thansize. If chars atsize-1andsizeis a surrogate pair, returns a CharSequence of lengthsize-1.- Parameters:
size- length of the result, should be greater than 0
-
-