public class StringTool
extends java.lang.Object
Constructor and Description |
---|
StringTool() |
Modifier and Type | Method and Description |
---|---|
static void |
appendRepeated(java.lang.StringBuilder builder,
char ch,
int count)
Insert repeated occurrences of a given character at the end of a StringBuilder
|
static IntIterator |
codePoints(java.lang.CharSequence value) |
static UnicodeString |
compress(char[] in,
int offset,
int len,
boolean compressWS)
Attempt to compress a UnicodeString consisting entirely of whitespace.
|
static boolean |
containsSurrogates(java.lang.String str)
Ask whether a string contains astral characters (represented as surrogate pairs)
|
static void |
copy16to24(char[] source,
int sourcePos,
byte[] dest,
int destPos,
int count)
Copy from an array of 16-bit characters to an array holding 16-bit characters.
|
static void |
copy8to16(byte[] source,
int sourcePos,
char[] dest,
int destPos,
int count)
Copy from an array of 8-bit characters to an array holding 16-bit characters.
|
static void |
copy8to24(byte[] source,
int sourcePos,
byte[] dest,
int destPos,
int count)
Copy from an array of 8-bit characters to an array holding 24-bit characters,
organised as three bytes per character
The caller is responsible for ensuring that the offsets are in range and that the
destination array is large enough.
|
static java.lang.String |
diagnosticDisplay(java.lang.String s)
Produce a diagnostic representation of the contents of the string
|
static int[] |
expand(UnicodeString s)
Expand a string into an array of 32-bit characters
|
static UnicodeString |
fromCharSequence(java.lang.CharSequence chars) |
static UnicodeString |
fromCodePoints(int[] codes,
int used)
Contract an array of integers containing Unicode codepoints into a string
|
static UnicodeString |
fromLatin1(java.lang.String str) |
static int |
getStringLength(java.lang.CharSequence s)
Get the length of a string, as defined in XPath.
|
static int |
lastCodePoint(UnicodeString str)
Get the last codepoint in a UnicodeString
|
static long |
lastIndexOf(UnicodeString str,
int codePoint)
Get the position of the last occurrence of a given codepoint within a string
|
static void |
prependRepeated(java.lang.StringBuilder builder,
char ch,
int count)
Insert repeated occurrences of a given character at the start of a StringBuilder
|
static void |
prependWideChar(java.lang.StringBuilder builder,
int ch)
Insert a wide character (surrogate pair) at the start of a StringBuilder
|
static int |
requireInt(long value)
Utility method for use where strings longer than 2^31 characters cannot yet be handled.
|
public static int getStringLength(java.lang.CharSequence s)
s
- The string whose length is requiredpublic static int[] expand(UnicodeString s)
s
- the string to be expandedpublic static boolean containsSurrogates(java.lang.String str)
str
- the string to be testedpublic static UnicodeString fromCodePoints(int[] codes, int used)
codes
- an array of integers representing the Unicode code pointsused
- the number of items in the array that are actually usedpublic static UnicodeString fromCharSequence(java.lang.CharSequence chars)
public static UnicodeString fromLatin1(java.lang.String str)
public static IntIterator codePoints(java.lang.CharSequence value)
public static java.lang.String diagnosticDisplay(java.lang.String s)
s
- the stringpublic static void prependWideChar(java.lang.StringBuilder builder, int ch)
builder
- the string builderch
- the codepoint of the character to be insertedpublic static void prependRepeated(java.lang.StringBuilder builder, char ch, int count)
builder
- the string builderch
- the character to be insertedcount
- the number of repetitionspublic static void appendRepeated(java.lang.StringBuilder builder, char ch, int count)
builder
- the string builderch
- the character to be insertedcount
- the number of repetitionspublic static int lastCodePoint(UnicodeString str)
str
- the input stringjava.lang.IndexOutOfBoundsException
- if the string is emptypublic static long lastIndexOf(UnicodeString str, int codePoint)
str
- the input stringcodePoint
- the sought codepointpublic static int requireInt(long value)
value
- the actual value of a character position within a string, or the length of
a stringjava.lang.UnsupportedOperationException
- if the supplied value exceeds Integer.MAX_VALUE
public static UnicodeString compress(char[] in, int offset, int len, boolean compressWS)
in
- the Unicode string to be compressedoffset
- the start position of the substring we are interested inlen
- the length of the substring we are interested incompressWS
- set to true if whitespace compression is to be attemptedpublic static void copy8to16(byte[] source, int sourcePos, char[] dest, int destPos, int count)
source
- the source arraysourcePos
- the position in the source array where copying is to startdest
- the destination arraydestPos
- the position in the destination array where copying is to startcount
- the number of characters (codepoints) to copypublic static void copy8to24(byte[] source, int sourcePos, byte[] dest, int destPos, int count)
source
- the source arraysourcePos
- the position in the source array where copying is to startdest
- the destination array, using three bytes per codepointdestPos
- the codepoint position (not byte position) in the destination array where
copying is to startcount
- the number of characters (codepoints) to copypublic static void copy16to24(char[] source, int sourcePos, byte[] dest, int destPos, int count)
source
- the source array. The caller is responsible for ensuring that this
contains no surrogatessourcePos
- the position in the source array where copying is to startdest
- the destination arraydestPos
- the position in the destination array where copying is to startcount
- the number of characters (codepoints) to copyCopyright (c) 2004-2022 Saxonica Limited. All rights reserved.