@Public public final class BinaryString extends BinarySection implements Comparable<BinaryString>
MemorySegment
s.Modifier and Type | Field and Description |
---|---|
static BinaryString |
EMPTY_UTF8 |
HIGHEST_FIRST_BIT, HIGHEST_SECOND_TO_EIGHTH_BIT, MAX_FIX_PART_DATA_SIZE, offset, segments, sizeInBytes
Constructor and Description |
---|
BinaryString(MemorySegment[] segments,
int offset,
int sizeInBytes) |
Modifier and Type | Method and Description |
---|---|
static BinaryString |
blankString(int length)
Creates a
BinaryString instance that contains `length` spaces. |
byte |
byteAt(int index)
Returns the
byte value at the specified index. |
int |
compareTo(BinaryString other)
Compares two strings lexicographically.
|
boolean |
contains(BinaryString s)
Returns true if and only if this BinaryString contains the specified sequence of bytes
values.
|
BinaryString |
copy()
Copy a new
BinaryString . |
static String |
decodeUTF8(byte[] input,
int offset,
int byteLen) |
static String |
decodeUTF8(MemorySegment input,
int offset,
int byteLen) |
static int |
decodeUTF8Strict(byte[] sa,
int sp,
int len,
char[] da) |
static int |
decodeUTF8Strict(MemorySegment segment,
int sp,
int len,
char[] da) |
static String |
defaultDecodeUTF8(byte[] bytes,
int offset,
int len) |
static int |
defaultEncodeUTF8(String str,
byte[] bytes) |
static byte[] |
encodeUTF8(String str)
This method must have the same result with JDK's String.getBytes.
|
static int |
encodeUTF8(String str,
byte[] bytes) |
boolean |
endsWith(BinaryString suffix)
Tests if this BinaryString ends with the specified suffix.
|
static BinaryString |
fromAddress(MemorySegment[] segments,
int offset,
int numBytes) |
static BinaryString |
fromBytes(byte[] bytes)
Creates a
BinaryString instance from the given UTF-8 bytes. |
static BinaryString |
fromBytes(byte[] bytes,
int offset,
int numBytes)
Creates a
BinaryString instance from the given UTF-8 bytes with offset and number of
bytes. |
static BinaryString |
fromString(String str) |
int |
indexOf(BinaryString str,
int fromIndex)
Returns the index within this string of the first occurrence of the specified substring,
starting at the specified index.
|
int |
numChars()
Returns the number of UTF-8 code points in the string.
|
boolean |
startsWith(BinaryString prefix)
Tests if this BinaryString starts with the specified prefix.
|
BinaryString |
substring(int beginIndex,
int endIndex)
Returns a binary string that is a substring of this binary string.
|
BinaryString |
toLowerCase()
Converts all of the characters in this
BinaryString to lower case. |
String |
toString() |
BinaryString |
toUpperCase()
Converts all of the characters in this
BinaryString to upper case. |
BinaryString |
trim()
Returns a string whose value is this string, with any leading and trailing whitespace
removed.
|
equals, getOffset, getSegments, getSizeInBytes, hashCode, pointTo, pointTo, toBytes
public static final BinaryString EMPTY_UTF8
public BinaryString(MemorySegment[] segments, int offset, int sizeInBytes)
public static BinaryString fromAddress(MemorySegment[] segments, int offset, int numBytes)
@Nullable public static BinaryString fromString(String str)
public static BinaryString fromBytes(byte[] bytes)
BinaryString
instance from the given UTF-8 bytes.public static BinaryString fromBytes(byte[] bytes, int offset, int numBytes)
BinaryString
instance from the given UTF-8 bytes with offset and number of
bytes.public static BinaryString blankString(int length)
BinaryString
instance that contains `length` spaces.public int compareTo(@Nonnull BinaryString other)
compareTo
in interface Comparable<BinaryString>
public int numChars()
public byte byteAt(int index)
byte
value at the specified index. An index ranges from 0
to
sizeInBytes - 1
.index
- the index of the byte
value.byte
value at the specified index of this UTF-8 bytes.IndexOutOfBoundsException
- if the index
argument is negative or not less
than the length of this UTF-8 bytes.public BinaryString copy()
BinaryString
.public BinaryString substring(int beginIndex, int endIndex)
beginIndex
and extends to the character at index endIndex - 1
.
Examples:
fromString("hamburger").substring(4, 8) returns binary string "urge" fromString("smiles").substring(1, 5) returns binary string "mile"
beginIndex
- the beginning index, inclusive.endIndex
- the ending index, exclusive.public boolean contains(BinaryString s)
s
- the sequence to search fors
, false otherwisepublic boolean startsWith(BinaryString prefix)
prefix
- the prefix.true
if the bytes represented by the argument is a prefix of the bytes
represented by this string; false
otherwise. Note also that true
will be
returned if the argument is an empty BinaryString or is equal to this BinaryString
object as determined by the BinarySection.equals(Object)
method.public boolean endsWith(BinaryString suffix)
suffix
- the suffix.true
if the bytes represented by the argument is a suffix of the bytes
represented by this object; false
otherwise. Note that the result will be true
if the argument is the empty string or is equal to this BinaryString
object
as determined by the BinarySection.equals(Object)
method.public BinaryString trim()
public int indexOf(BinaryString str, int fromIndex)
str
- the substring to search for.fromIndex
- the index from which to start the search.-1
if there is no such occurrence.public BinaryString toUpperCase()
BinaryString
to upper case.BinaryString
, converted to uppercase.public BinaryString toLowerCase()
BinaryString
to lower case.BinaryString
, converted to lowercase.public static byte[] encodeUTF8(String str)
public static int encodeUTF8(String str, byte[] bytes)
public static int defaultEncodeUTF8(String str, byte[] bytes)
public static String decodeUTF8(byte[] input, int offset, int byteLen)
public static int decodeUTF8Strict(byte[] sa, int sp, int len, char[] da)
public static String decodeUTF8(MemorySegment input, int offset, int byteLen)
public static int decodeUTF8Strict(MemorySegment segment, int sp, int len, char[] da)
public static String defaultDecodeUTF8(byte[] bytes, int offset, int len)
Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.