Top Fields Constructors Methods
com.ibm.icu.impl

public final Class Utility

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.ArrayList, .Iterator, .Locale, java.util.regex.Pattern, com.ibm.icu.lang.UCharacter, com.ibm.icu.text.Replaceable, .UTF16, .UnicodeMatcher, com.ibm.icu.util.ICUUncheckedIOException

Field Summary

Modifier and TypeField and Description
private static final char
private static final char
pack-priv static final char[]
private static final char
ESCAPE

The ESCAPE character is used during run-length encoding.

pack-priv static final byte
ESCAPE_BYTE

The ESCAPE_BYTE character is used during run-length encoding.

pack-priv static final char[]
public static String
private static final int
private static final char[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static final int
_digit16(int c)

private static final int
_digit8(int c)

public static int

Returns:

the result
addExact
(int
the first value
x
,
int
the second value
y
)

This implementation is equivalent to Java 8+ Math#addExact(int, int)

private static final <T extends Appendable> void
appendEncodedByte(T buffer, byte value, byte[]
A two-element array, with state[0] == 0 if this is the first byte of a pair, or state[0] != 0 if this is the second byte of a pair, in which case state[1] is the first byte.
state
)

Append a byte to the given Appendable, packing two bytes into each character.

private static final <T extends Appendable> void
appendInt(T buffer, int value)

public static <T extends Appendable> T

Returns:

a reference to result
appendNumber
(T
the digits of the number are appended here
result
,
int
the number to be converted to digits; may be negative. If negative, a '-' is prepended to the digits.
n
,
int
a radix from 2 to 36 inclusive.
radix
,
int
the minimum number of digits, not including any '-', to produce. Values less than 2 have no effect. One digit is always emitted regardless of this parameter.
minDigits
)

Append a number to the given Appendable in the given radix.

public static <A extends Appendable> A
appendTo(CharSequence string, A appendable)

Appends a CharSequence to an Appendable, converting IOException to ICUUncheckedIOException.

public static void
appendToRule(StringBuffer
the string to append the character to
rule
,
int
the character to append, or (int)-1 if none.
c
,
boolean
if true, then the given character should not be quoted or escaped. Usually this means it is a syntactic element such as > or $
isLiteral
,
boolean
if true, then unprintable characters should be escaped using escapeUnprintable(). These escapes will appear outside of quotes.
escapeUnprintable
,
StringBuffer
a buffer which is used to build up quoted substrings. The caller should initially supply an empty buffer, and thereafter should not modify the buffer. The buffer should be cleared out by, at the end, calling this method with a literal character (which may be -1).
quoteBuf
)

Append a character to a rule that is being built up.

public static void
appendToRule(StringBuffer rule, String text, boolean isLiteral, boolean escapeUnprintable, StringBuffer quoteBuf)

Append the given string to the rule.

public static void
appendToRule(StringBuffer rule, UnicodeMatcher matcher, boolean escapeUnprintable, StringBuffer quoteBuf)

Given a matcher reference, which may be null, append its pattern as a literal to the given rule.

public static final boolean
arrayEquals(Object[] source, Object target)

Convenience utility to compare two Object[]s.

public static final boolean
arrayEquals(int[] source, Object target)

Convenience utility to compare two int[]s Ought to be in System

public static final boolean
arrayEquals(double[] source, Object target)

Convenience utility to compare two double[]s Ought to be in System

public static final boolean
arrayEquals(byte[] source, Object target)

public static final boolean
arrayEquals(Object source, Object target)

Convenience utility to compare two Object[]s Ought to be in System

public static final boolean
arrayRegionMatches(Object[] source, int sourceStart, Object[] target, int targetStart, int
the length to compare. The start indices and start+len must be valid.
len
)

Convenience utility to compare two Object[]s Ought to be in System.

public static final boolean
arrayRegionMatches(char[] source, int sourceStart, char[] target, int targetStart, int
the length to compare. The start indices and start+len must be valid.
len
)

Convenience utility to compare two Object[]s Ought to be in System.

public static final boolean
arrayRegionMatches(int[] source, int sourceStart, int[] target, int targetStart, int
the length to compare. The start indices and start+len must be valid. Ought to be in System
len
)

Convenience utility to compare two int[]s.

public static final boolean
arrayRegionMatches(double[] source, int sourceStart, double[] target, int targetStart, int
the length to compare. The start indices and start+len must be valid. Ought to be in System
len
)

Convenience utility to compare two arrays of doubles.

public static final boolean
arrayRegionMatches(byte[] source, int sourceStart, byte[] target, int targetStart, int len)

public static final String
arrayToRLEString(int[] a)

Construct a string representing an int array.

public static final String
arrayToRLEString(short[] a)

Construct a string representing a short array.

public static final String
arrayToRLEString(char[] a)

Construct a string representing a char array.

public static final String
arrayToRLEString(byte[] a)

Construct a string representing a byte array.

public static boolean
charSequenceEquals(CharSequence a, CharSequence b)

Returns whether the chars in the two CharSequences are equal.

public static int
charSequenceHashCode(CharSequence value)

Returns a hash code for a CharSequence that is equivalent to calling charSequence.toString().hashCode()

public static <T extends Comparable<T>> int
checkCompare(T a, T b)

Convenience utility.

public static int
checkHash(Object a)

Convenience utility.

private static int
codePointAndLength(int c, int length)

private static int
codePointAndLength(int c, int start, int limit)

public static final int

Returns:

0 if equals, 1 if source is greater than target and -1 otherwise
compareUnsigned
(int
32 bit unsigned integer
source
,
int
32 bit unsigned integer
target
)

Compares 2 unsigned integers

public static int
cpFromCodePointAndLength(int cpAndLength)

private static final <T extends Appendable> void
encodeRun(T buffer, int value, int
The length of the run; must be > 0 && <= 0xFFFF.
length
)

Encode a run, possibly a degenerate run (of < 4 values).

private static final <T extends Appendable> void
encodeRun(T buffer, short value, int
The length of the run; must be > 0 && <= 0xFFFF.
length
)

Encode a run, possibly a degenerate run (of < 4 values).

private static final <T extends Appendable> void
encodeRun(T buffer, byte value, int
The length of the run; must be > 0 && <= 0xFF.
length
,
byte[] state)

Encode a run, possibly a degenerate run (of < 4 values).

public static final String
escape(String s)

Convert characters outside the range U+0020 to U+007F to Unicode escapes, and convert backslash to a double backslash.

public static <T extends Appendable> T

Returns:

result
escape
(T result, int c)

Escapes one code point using <backslash>uxxxx notation for U+0000 to U+FFFF and <backslash>Uxxxxxxxx for U+10000 and above.

public static <T extends Appendable> boolean
escapeUnprintable(T result, int c)

Escapes one unprintable code point using <backslash>uxxxx notation for U+0000 to U+FFFF and <backslash>Uxxxxxxxx for U+10000 and above.

public static final String
format1ForSource(String s)

Format a String for representation in a source file.

public static final String
formatForSource(String s)

Format a String for representation in a source file.

public static String

Returns:

A string from hex numbers.
fromHex
(String
String of hex numbers.
string
,
int
Minimal length.
minLength
,
String
Separator.
separator
)

Parse a list of hex numbers and return a string

public static String

Returns:

A string from hex numbers.
fromHex
(String
String of hex numbers.
string
,
int
Minimal length.
minLength
,
Pattern
Separator.
separator
)

Parse a list of hex numbers and return a string

pack-priv static final int
getInt(String s, int i)

public static String
hex(long ch)

Convert a char to 4 hex uppercase digits.

public static String
hex(long i, int places)

Supplies a zero-padded hex representation of an integer (without 0x)

public static String
hex(CharSequence s)

Convert a string to comma-separated groups of 4 hex uppercase digits.

public static <S extends CharSequence, U extends CharSequence, T extends Appendable> T
hex(S s, int width, U separator, boolean useCodePoints, T result)

Convert a string to separated groups of hex uppercase digits.

public static String
hex(byte[] o, int start, int end, String separator)

public static <S extends CharSequence> String
hex(S s, int width, S separator)

Convert a string to comma-separated groups of 4 hex uppercase digits.

public static final byte

Returns:

the bit number of the highest bit, with 0 being the low order bit, or -1 if n is not positive
highBit
(int
is the integer
n
)

Find the highest bit in a positive integer.

public static boolean
isUnprintable(int c)

Return true if the character is NOT printable ASCII.

public static String

Returns:

a new String that is composed of the elements separated by the delimiter
joinStrings
(CharSequence
the delimiter that separates each element
delimiter
,
Iterable<? extends CharSequence>
the elements to join together.
elements
)

Java 8+ String#join(CharSequence, Iterable<? extends CharSequence>) compatible method for Java 7 env.

public static int
public static int

Returns:

the index of target at which source first occurs, or -1 if not found
lookup
(String
the string to search for
source
,
String[]
the array of zero or more strings in which to look for source
target
)

Look up a given string in a string array.

public static boolean

Returns:

true if 'ch' is seen preceded by zero or more whitespace characters.
parseChar
(String
the string to be parsed
id
,
int[]
INPUT-OUTPUT parameter. On input, pos[0] is the offset of the first character to be parsed. On output, pos[0] is the index after the last parsed character. If the parse fails, pos[0] will be unchanged.
pos
,
char
the non-whitespace character to be parsed.
ch
)

Parse a single non-whitespace character 'ch', optionally preceded by whitespace.

public static int
parseInteger(String rule, int[]
INPUT-OUTPUT parameter. On input, the first character to parse. On output, the character after the last parsed character.
pos
,
int limit)

Parse an integer at pos, either of the form \d+ or of the form 0x[0-9A-Fa-f]+ or 0[0-7]+, that is, in standard decimal, hex, or octal format.

public static int

Returns:

a non-negative parsed number, or -1 upon parse failure. Parse fails if there are no digits, that is, if pos[0] does not point to a valid digit on entry, or if the number to be parsed does not fit into a 31-bit unsigned integer.
parseNumber
(String
the text to be parsed
text
,
int[]
INPUT-OUTPUT parameter. On entry, pos[0] is the offset within text at which to start parsing; it should point to a valid digit. On exit, pos[0] is the offset after the last parsed character. If the parse failed, it will be unchanged on exit. Must be >= 0 on entry.
pos
,
int
the radix in which to parse; must be >= 2 and <= 36.
radix
)

Parse an unsigned 31-bit integer at the given offset.

public static int

Returns:

the position after the last character parsed, or -1 if the parse failed
parsePattern
(String rule, int pos, int limit, String
must only contain lowercase characters, which will match their uppercase equivalents as well. A space character matches one or more required spaces. A '~' character matches zero or more optional spaces. A '#' character matches an integer and stores it in parsedInts, which the caller must ensure has enough capacity.
pattern
,
int[]
array to receive parsed integers. Caller must ensure that parsedInts.length is >= the number of '#' signs in 'pattern'.
parsedInts
)

Parse a pattern string starting at offset pos.

public static int

Returns:

index after last parsed character, or -1 on parse failure.
parsePattern
(String
pattern that controls parsing
pat
,
Replaceable
text to be parsed, starting at index
text
,
int
offset to first character to parse
index
,
int
offset after last character to parse
limit
)

Parse a pattern string within the given Replaceable and a parsing pattern.

public static String

Returns:

the Unicode identifier, or null if there is no valid identifier at pos[0].
parseUnicodeIdentifier
(String
the string to parse
str
,
int[]
INPUT-OUTPUT parameter. On INPUT, pos[0] is the first character to examine. It must be less than str.length(), and it must not point to a whitespace character. That is, must have pos[0] < str.length(). On OUTPUT, the position after the last parsed character.
pos
)

Parse a Unicode identifier from the given string at the given position.

public static int

Returns:

Offset of the first character in setOfChars found, or -1 if not found.
quotedIndexOf
(String
text to be searched
text
,
int
the beginning index, inclusive; 0 <= start <= limit.
start
,
int
the ending index, exclusive; start <= limit <= text.length().
limit
,
String
string with one or more distinct characters
setOfChars
)

Returns the index of the first character in a set, ignoring quoted text.

private static <T extends Appendable> void
recursiveAppendNumber(T
is the Appendable to append to
result
,
int
is the positive integer
n
,
int
is the radix, from 2 to 36 inclusive
radix
,
int
is the minimum number of digits to append.
minDigits
)

Append the digits of a positive integer to the given Appendable in the given radix.

public static String
repeat(String
String to be duplicated.
s
,
int
Number of times to duplicate a string.
count
)

Utility to duplicate a string count times

public static final byte[]
RLEStringToByteArray(String s)

Construct an array of bytes from a run-length encoded string.

public static final char[]
RLEStringToCharArray(String s)

Construct an array of shorts from a run-length encoded string.

public static final int[]
RLEStringToIntArray(String s)

Construct an array of ints from a run-length encoded string.

public static final short[]
RLEStringToShortArray(String s)

Construct an array of shorts from a run-length encoded string.

public static final boolean
sameObjects(Object a, Object b)

Trivial reference equality.

public static boolean

Returns:

true for control codes and for surrogate and noncharacter code points
shouldAlwaysBeEscaped
(int c)

public static void
split(String
the string to split
s
,
char
the character on which to split. Occurrences of this character are not included in the output
divider
,
String[]
an array to receive the substrings between instances of divider. It must be large enough on entry to accommodate all output. Adjacent instances of the divider character will place empty strings into output. Before returning, output is padded out with empty strings.
output
)

Split a string into pieces based on the given divider character

public static String[]

Returns:

output an array to receive the substrings between instances of divider. Adjacent instances of the divider character will place empty strings into output.
split
(String
the string to split
s
,
char
the character on which to split. Occurrences of this character are not included in the output
divider
)

Split a string into pieces based on the given divider character

public static String[]
splitString(String src, String target)

public static String[]
splitWhitespace(String src)

Split the string at runs of ascii whitespace characters.

public static String
unescape(CharSequence s)

Convert all escapes in a given string using unescapeAndLengthAt().

public static int

Returns:

the code point and length, or -1 on error.
unescapeAndLengthAt
(CharSequence s, int
the offset to the character after the backslash.
offset
)

Converts an escape to a code point value.

private static int
unescapeAndLengthAt(CharSequence s, int offset, int length)

public static String
unescapeLeniently(CharSequence s)

Convert all escapes in a given string using unescapeAndLengthAt().

public static String
valueOf(int[] source)

Utility method to take a int[] containing codepoints and return a string representation with code units.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait