public class StringKit
extends java.lang.Object
COMMON_PUNCTUATION
and LATIN_LETTERS_UPPER
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BOX_DRAWING |
static java.lang.String |
BOX_DRAWING_DOUBLE |
static java.lang.String |
BOX_DRAWING_SINGLE |
static java.lang.String |
COMMON_PUNCTUATION |
static java.lang.String |
CURRENCY |
static java.lang.String |
CYRILLIC_LETTERS |
static java.lang.String |
CYRILLIC_LETTERS_LOWER |
static java.lang.String |
CYRILLIC_LETTERS_UPPER |
static java.lang.String |
DIGITS |
static java.lang.String |
ENGLISH_LETTERS |
static java.lang.String |
ENGLISH_LETTERS_LOWER |
static java.lang.String |
ENGLISH_LETTERS_UPPER |
static java.lang.String |
GREEK_LETTERS |
static java.lang.String |
GREEK_LETTERS_LOWER
Includes both lower-case forms for Sigma, 'ς' and 'σ', but this matches the two upper-case Sigma in
GREEK_LETTERS_UPPER . |
static java.lang.String |
GREEK_LETTERS_UPPER
Includes the letter Sigma, 'Σ', twice because it has two lower-case forms in
GREEK_LETTERS_LOWER . |
static java.lang.String |
GROUPING_SIGNS_CLOSE
An index in
GROUPING_SIGNS_OPEN can be used here to find the closing char for that opening one. |
static java.lang.String |
GROUPING_SIGNS_OPEN
Can be used to match an index with one in
GROUPING_SIGNS_CLOSE to find the closing char (this way only). |
static char[] |
hexDigits
Constant storing the 16 hexadecimal digits, as char values, in order.
|
static java.lang.String |
LATIN_EXTENDED_LETTERS |
static java.lang.String |
LATIN_EXTENDED_LETTERS_LOWER |
static java.lang.String |
LATIN_EXTENDED_LETTERS_UPPER |
static java.lang.String |
LATIN_LETTERS |
static java.lang.String |
LATIN_LETTERS_LOWER |
static java.lang.String |
LATIN_LETTERS_UPPER |
static java.lang.String |
LETTERS |
static java.lang.String |
LETTERS_AND_NUMBERS |
static java.lang.String |
LETTERS_LOWER |
static java.lang.String |
LETTERS_UPPER |
static java.lang.String |
MARKS |
static java.lang.String |
mask16 |
static java.lang.String |
mask32 |
static java.lang.String |
mask64 |
static java.lang.String |
mask8 |
static java.lang.String |
MODERN_PUNCTUATION |
static regexodus.Pattern |
nonSpacePattern |
static java.lang.String |
PERMISSIBLE_CHARS
A constant containing only chars that are reasonably likely to be supported by broad fonts and thus display-able.
|
static java.lang.String |
PUNCTUATION |
static java.lang.String |
SPACING |
static java.lang.String |
TECHNICAL_PUNCTUATION |
static java.lang.String |
UNCOMMON_PUNCTUATION |
static java.lang.String |
VISUAL_SYMBOLS |
static regexodus.Pattern |
whitespacePattern |
Constructor and Description |
---|
StringKit() |
Modifier and Type | Method and Description |
---|---|
static java.lang.StringBuilder |
appendHex(java.lang.StringBuilder builder,
byte number) |
static java.lang.StringBuilder |
appendHex(java.lang.StringBuilder builder,
char number) |
static java.lang.StringBuilder |
appendHex(java.lang.StringBuilder builder,
double number) |
static java.lang.StringBuilder |
appendHex(java.lang.StringBuilder builder,
float number) |
static java.lang.StringBuilder |
appendHex(java.lang.StringBuilder builder,
int number) |
static java.lang.StringBuilder |
appendHex(java.lang.StringBuilder builder,
long number) |
static java.lang.StringBuilder |
appendHex(java.lang.StringBuilder builder,
short number) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
boolean... elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
byte... elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
char... elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
java.lang.CharSequence... elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
java.util.Collection<? extends java.lang.CharSequence> elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
double... elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
float... elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
int... elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
java.lang.Iterable<?> elements)
Joins the items in
elements by calling their toString method on them (or just using the String "null" for
null items), and separating each item with delimiter . |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
long... elements) |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
java.lang.Object[] elements)
Joins the items in
elements by calling their toString method on them (or just using the String "null" for
null items), and separating each item with delimiter . |
static java.lang.StringBuilder |
appendJoined(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
short... elements) |
static java.lang.StringBuilder |
appendJoinedAlt(java.lang.StringBuilder sb,
boolean... elements)
Joins the boolean array
elements without delimiters into a String, using "1" for true and "0" for false. |
static java.lang.StringBuilder |
appendJoinedAlt(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
long... elements)
Like
appendJoined(StringBuilder, CharSequence, long...) , but this appends an 'L' to each number so they can be read in by Java. |
static java.lang.StringBuilder |
appendJoinedArrays(java.lang.StringBuilder sb,
java.lang.CharSequence delimiter,
char[]... elements) |
static byte |
b64DecodeByte(char[] data,
int offset)
Decodes 2 characters from data starting from offset to get a byte encoded as base-64.
|
static char |
b64DecodeChar(char[] data,
int offset)
Decodes 3 characters from data starting from offset to get a char encoded as base-64.
|
static double |
b64DecodeDouble(char[] data,
int offset)
Decodes 11 characters from data starting from offset to get a double encoded as base-64.
|
static float |
b64DecodeFloat(char[] data,
int offset)
Decodes 6 characters from data starting from offset to get a float encoded as base-64.
|
static int |
b64DecodeInt(char[] data,
int offset)
Decodes 6 characters from data starting from offset to get an int encoded as base-64.
|
static long |
b64DecodeLong(char[] data,
int offset)
Decodes 11 characters from data starting from offset to get a long encoded as base-64.
|
static short |
b64DecodeShort(char[] data,
int offset)
Decodes 3 characters from data starting from offset to get a short encoded as base-64.
|
static char[] |
b64Encode(byte number,
int offset,
char[] buf)
Base-64 encodes number and stores that string representation in buf starting at offset; uses 2 chars.
|
static char[] |
b64Encode(char glyph,
int offset,
char[] buf)
Base-64 encodes glyph and stores that string representation in buf starting at offset; uses 3 chars.
|
static char[] |
b64Encode(double number,
int offset,
char[] buf)
Base-64 encodes number and stores that string representation in buf starting at offset; uses 11 chars.
|
static char[] |
b64Encode(float number,
int offset,
char[] buf)
Base-64 encodes number and stores that string representation in buf starting at offset; uses 6 chars.
|
static char[] |
b64Encode(int number,
int offset,
char[] buf)
Base-64 encodes number and stores that string representation in buf starting at offset; uses 6 chars.
|
static char[] |
b64Encode(long number,
int offset,
char[] buf)
Base-64 encodes number and stores that string representation in buf starting at offset; uses 11 chars.
|
static char[] |
b64Encode(short number,
int offset,
char[] buf)
Base-64 encodes number and stores that string representation in buf starting at offset; uses 3 chars.
|
static java.lang.String |
bin(byte number) |
static java.lang.String |
bin(char number) |
static java.lang.String |
bin(int number) |
static java.lang.String |
bin(long number) |
static java.lang.String |
bin(short number) |
static java.lang.String |
capitalize(java.lang.CharSequence original)
Capitalizes Each Word In The Parameter
original , Returning A New String. |
static boolean |
contains(java.lang.CharSequence text,
char[] search)
Searches text for the exact contents of the char array search; returns true if text contains search.
|
static int |
containsPart(java.lang.CharSequence text,
char[] search)
Tries to find as much of the char array
search in the CharSequence text , always starting from the
beginning of search (if the beginning isn't found, then it finds nothing), and returns the length of the found
part of search (0 if not found). |
static int |
containsPart(java.lang.CharSequence text,
char[] search,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix)
Tries to find as much of the sequence
prefix search suffix as it can in text, where prefix and suffix are
CharSequences for some reason and search is a char array. |
static java.lang.String |
correctABeforeVowel(java.lang.CharSequence text)
A simple method that looks for any occurrences of the word 'a' followed by some non-zero amount of whitespace and
then any vowel starting the following word (such as 'a item'), then replaces each such improper 'a' with 'an'
(such as 'an item').
|
static int |
count(java.lang.String source,
int search)
Scans repeatedly in
source for the codepoint search (which is usually a char literal), not
scanning the same section twice, and returns the number of instances of search that were found, or 0 if source is
null. |
static int |
count(java.lang.String source,
int search,
int startIndex,
int endIndex)
Scans repeatedly in
source (only using the area from startIndex, inclusive, to endIndex, exclusive) for
the codepoint search (which is usually a char literal), not scanning the same section twice, and returns
the number of instances of search that were found, or 0 if source is null or if the searched area is empty. |
static int |
count(java.lang.String source,
java.lang.String search)
Scans repeatedly in
source for the String search , not scanning the same char twice except as part
of a larger String, and returns the number of instances of search that were found, or 0 if source is null or if
search is null or empty. |
static int |
count(java.lang.String source,
java.lang.String search,
int startIndex,
int endIndex)
Scans repeatedly in
source (only using the area from startIndex, inclusive, to endIndex, exclusive) for
the String search , not scanning the same char twice except as part of a larger String, and returns the
number of instances of search that were found, or 0 if source or search is null or if the searched area is empty. |
static java.lang.String |
hex(byte number) |
static java.lang.String |
hex(byte[] numbers) |
static java.lang.String |
hex(char number) |
static java.lang.String |
hex(char[] numbers) |
static java.lang.String |
hex(double number) |
static java.lang.String |
hex(double[] numbers) |
static java.lang.String |
hex(float number) |
static java.lang.String |
hex(float[] numbers) |
static java.lang.String |
hex(int number) |
static java.lang.String |
hex(int[] numbers) |
static java.lang.String |
hex(long number) |
static java.lang.String |
hex(long[] numbers) |
static java.lang.String |
hex(short number) |
static java.lang.String |
hex(short[] numbers) |
static java.lang.String |
hexHash(boolean... array) |
static java.lang.String |
hexHash(byte... array) |
static java.lang.String |
hexHash(char... array) |
static java.lang.String |
hexHash(int... array) |
static java.lang.String |
hexHash(long... array) |
static java.lang.String |
hexHash(short... array) |
static int |
indexOf(java.lang.CharSequence text,
regexodus.Pattern regex) |
static int |
indexOf(java.lang.CharSequence text,
regexodus.Pattern regex,
int beginIndex) |
static int |
indexOf(java.lang.CharSequence text,
java.lang.String regex) |
static int |
indexOf(java.lang.CharSequence text,
java.lang.String regex,
int beginIndex) |
static int |
intFromBin(java.lang.CharSequence cs)
Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent,
reading at most 32 characters and returning the result if valid or 0 otherwise.
|
static int |
intFromBin(java.lang.CharSequence cs,
int start,
int end)
Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent,
reading at most 32 characters and returning the result if valid or 0 otherwise.
|
static int |
intFromDec(java.lang.CharSequence cs)
Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the
int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0
if nothing could be read.
|
static int |
intFromDec(java.lang.CharSequence cs,
int start,
int end)
Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the
int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0
if nothing could be read.
|
static int |
intFromHex(char[] cs,
int start,
int end)
Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start
and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result
if valid, or 0 if nothing could be read.
|
static int |
intFromHex(java.lang.CharSequence cs)
Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start
and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result
if valid, or 0 if nothing could be read.
|
static int |
intFromHex(java.lang.CharSequence cs,
int start,
int end)
Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start
and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result
if valid, or 0 if nothing could be read.
|
static java.lang.String |
join(java.lang.CharSequence delimiter,
boolean... elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
byte... elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
char... elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
java.lang.CharSequence... elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
java.util.Collection<? extends java.lang.CharSequence> elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
double... elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
float... elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
int... elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
java.lang.Iterable<?> elements)
Joins the items in
elements by calling their toString method on them (or just using the String "null" for
null items), and separating each item with delimiter . |
static java.lang.String |
join(java.lang.CharSequence delimiter,
long... elements) |
static java.lang.String |
join(java.lang.CharSequence delimiter,
java.lang.Object[] elements)
Joins the items in
elements by calling their toString method on them (or just using the String "null" for
null items), and separating each item with delimiter . |
static java.lang.String |
join(java.lang.CharSequence delimiter,
short... elements) |
static java.lang.String |
joinAlt(boolean... elements)
Joins the boolean array
elements without delimiters into a String, using "1" for true and "0" for false. |
static java.lang.String |
joinAlt(java.lang.CharSequence delimiter,
long... elements)
Like
join(CharSequence, long...) , but this appends an 'L' to each number so they can be read in by Java. |
static java.lang.String |
joinArrays(java.lang.CharSequence delimiter,
char[]... elements) |
static long |
longFromBin(java.lang.CharSequence cs)
Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent,
reading at most 64 characters and returning the result if valid or 0 otherwise.
|
static long |
longFromBin(java.lang.CharSequence cs,
int start,
int end)
Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent,
reading at most 64 characters and returning the result if valid or 0 otherwise.
|
static long |
longFromDec(java.lang.CharSequence cs)
Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the
long they represent, reading at most 19 characters (20 if there is a sign) and returning the result if valid, or
0 if nothing could be read.
|
static long |
longFromDec(java.lang.CharSequence cs,
int start,
int end)
Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the
long they represent between the given positions
start and end , reading at most 19 characters (20
if there is a sign) or until end is reached and returning the result if valid, or 0 if nothing could be read. |
static long |
longFromHex(char[] cs,
int start,
int end)
Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and
returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result
if valid, or 0 if nothing could be read.
|
static long |
longFromHex(java.lang.CharSequence cs)
Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start
and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the
result if valid, or 0 if nothing could be read.
|
static long |
longFromHex(java.lang.CharSequence cs,
int start,
int end)
Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start
and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the
result if valid, or 0 if nothing could be read.
|
static java.lang.String |
padLeft(java.lang.String text,
char padChar,
int minimumLength)
If text is shorter than the given minimumLength, returns a String with text padded on the left with padChar until
it reaches that length; otherwise it simply returns text.
|
static java.lang.String |
padLeft(java.lang.String text,
int minimumLength)
If text is shorter than the given minimumLength, returns a String with text padded on the left with spaces until
it reaches that length; otherwise it simply returns text.
|
static java.lang.String |
padLeftStrict(java.lang.String text,
char padChar,
int totalLength)
Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on
its left side with padChar until totalLength is reached.
|
static java.lang.String |
padLeftStrict(java.lang.String text,
int totalLength)
Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on
its left side with spaces until totalLength is reached.
|
static java.lang.String |
padRight(java.lang.String text,
char padChar,
int minimumLength)
If text is shorter than the given minimumLength, returns a String with text padded on the right with padChar
until it reaches that length; otherwise it simply returns text.
|
static java.lang.String |
padRight(java.lang.String text,
int minimumLength)
If text is shorter than the given minimumLength, returns a String with text padded on the right with spaces until
it reaches that length; otherwise it simply returns text.
|
static java.lang.String |
padRightStrict(java.lang.String text,
char padChar,
int totalLength)
Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on
its right side with padChar until totalLength is reached.
|
static java.lang.String |
padRightStrict(java.lang.String text,
int totalLength)
Constructs a String with exactly the given totalLength by taking text (or a substring of it) and padding it on
its right side with spaces until totalLength is reached.
|
static java.lang.String |
replace(java.lang.CharSequence text,
java.lang.String before,
java.lang.String after) |
static java.lang.String |
safeSubstring(java.lang.String source,
int beginIndex,
int endIndex)
Like
String.substring(int, int) but returns "" instead of throwing any sort of Exception. |
static java.lang.String |
sentenceCase(java.lang.CharSequence original)
Attempts to scan for sentences in
original , capitalizes the first letter of each sentence, and otherwise
leaves the CharSequence untouched as it returns it as a String. |
static java.lang.String[] |
split(java.lang.String source,
java.lang.String delimiter)
Like
String.split(String) but doesn't use any regex for splitting (delimiter is a literal String). |
static java.util.List<java.lang.String> |
wrap(java.lang.CharSequence longText,
int width)
Word-wraps the given String (or other CharSequence, such as a StringBuilder) so it is split into zero or more
Strings as lines of text, with the given width as the maximum width for a line.
|
static java.util.List<java.lang.String> |
wrap(java.util.List<java.lang.String> receiving,
java.lang.CharSequence longText,
int width)
Word-wraps the given String (or other CharSequence, such as a StringBuilder) so it is split into zero or more
Strings as lines of text, with the given width as the maximum width for a line; appends the word-wrapped lines to
the given List of Strings and does not create a new List.
|
public static final java.lang.String mask64
public static final java.lang.String mask32
public static final java.lang.String mask16
public static final java.lang.String mask8
public static final regexodus.Pattern whitespacePattern
public static final regexodus.Pattern nonSpacePattern
public static final char[] hexDigits
public static final java.lang.String PERMISSIBLE_CHARS
public static final java.lang.String BOX_DRAWING_SINGLE
public static final java.lang.String BOX_DRAWING_DOUBLE
public static final java.lang.String BOX_DRAWING
public static final java.lang.String VISUAL_SYMBOLS
public static final java.lang.String DIGITS
public static final java.lang.String MARKS
public static final java.lang.String GROUPING_SIGNS_OPEN
GROUPING_SIGNS_CLOSE
to find the closing char (this way only).public static final java.lang.String GROUPING_SIGNS_CLOSE
GROUPING_SIGNS_OPEN
can be used here to find the closing char for that opening one.public static final java.lang.String COMMON_PUNCTUATION
public static final java.lang.String MODERN_PUNCTUATION
public static final java.lang.String UNCOMMON_PUNCTUATION
public static final java.lang.String TECHNICAL_PUNCTUATION
public static final java.lang.String PUNCTUATION
public static final java.lang.String CURRENCY
public static final java.lang.String SPACING
public static final java.lang.String ENGLISH_LETTERS_UPPER
public static final java.lang.String ENGLISH_LETTERS_LOWER
public static final java.lang.String ENGLISH_LETTERS
public static final java.lang.String LATIN_EXTENDED_LETTERS_UPPER
public static final java.lang.String LATIN_EXTENDED_LETTERS_LOWER
public static final java.lang.String LATIN_EXTENDED_LETTERS
public static final java.lang.String LATIN_LETTERS_UPPER
public static final java.lang.String LATIN_LETTERS_LOWER
public static final java.lang.String LATIN_LETTERS
public static final java.lang.String GREEK_LETTERS_UPPER
GREEK_LETTERS_LOWER
. This
lets you use one index for both lower and upper case, like with Latin and Cyrillic.public static final java.lang.String GREEK_LETTERS_LOWER
GREEK_LETTERS_UPPER
. This lets you use one index for both lower and upper case, like with Latin and
Cyrillic.public static final java.lang.String GREEK_LETTERS
public static final java.lang.String CYRILLIC_LETTERS_UPPER
public static final java.lang.String CYRILLIC_LETTERS_LOWER
public static final java.lang.String CYRILLIC_LETTERS
public static final java.lang.String LETTERS_UPPER
public static final java.lang.String LETTERS_LOWER
public static final java.lang.String LETTERS
public static final java.lang.String LETTERS_AND_NUMBERS
public static boolean contains(java.lang.CharSequence text, char[] search)
text
- a CharSequence, such as a String or StringBuilder, that might contain searchsearch
- a char array to try to find in textpublic static int containsPart(java.lang.CharSequence text, char[] search)
search
in the CharSequence text
, always starting from the
beginning of search (if the beginning isn't found, then it finds nothing), and returns the length of the found
part of search (0 if not found).text
- a CharSequence to search insearch
- a char array to look forpublic static int containsPart(java.lang.CharSequence text, char[] search, java.lang.CharSequence prefix, java.lang.CharSequence suffix)
prefix search suffix
as it can in text, where prefix and suffix are
CharSequences for some reason and search is a char array. Returns the length of the sequence it was able to
match, up to prefix.length() + search.length + suffix.length()
, or 0 if no part of the looked-for
sequence could be found.
text
- a CharSequence to search insearch
- a char array to look for, surrounded by prefix and suffixprefix
- a mandatory prefix before search, separated for some weird optimization reasonsuffix
- a mandatory suffix after search, separated for some weird optimization reasonpublic static java.lang.String join(java.lang.CharSequence delimiter, java.lang.CharSequence... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, java.util.Collection<? extends java.lang.CharSequence> elements)
public static java.lang.String joinArrays(java.lang.CharSequence delimiter, char[]... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, long... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, double... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, int... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, float... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, short... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, char... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, byte... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, boolean... elements)
public static java.lang.String join(java.lang.CharSequence delimiter, java.lang.Object[] elements)
elements
by calling their toString method on them (or just using the String "null" for
null items), and separating each item with delimiter
. Unlike other join methods in this class, this does
not take a vararg of Object items, since that would cause confusion with the overloads that take one object, such
as join(CharSequence, Iterable)
; it takes a non-vararg Object array instead.delimiter
- the String or other CharSequence to separate items in elements withelements
- the Object items to stringify and join into one String; if the array is null or empty, this
returns an empty String, and if items are null, they are shown as "null"public static java.lang.String join(java.lang.CharSequence delimiter, java.lang.Iterable<?> elements)
elements
by calling their toString method on them (or just using the String "null" for
null items), and separating each item with delimiter
. This can take any Iterable of any type for its
elements parameter.delimiter
- the String or other CharSequence to separate items in elements withelements
- the Object items to stringify and join into one String; if Iterable is null or empty, this
returns an empty String, and if items are null, they are shown as "null"public static java.lang.String joinAlt(boolean... elements)
elements
without delimiters into a String, using "1" for true and "0" for false.elements
- an array or vararg of booleanspublic static java.lang.String joinAlt(java.lang.CharSequence delimiter, long... elements)
join(CharSequence, long...)
, but this appends an 'L' to each number so they can be read in by Java.delimiter
- elements
- public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, java.lang.CharSequence... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, java.util.Collection<? extends java.lang.CharSequence> elements)
public static java.lang.StringBuilder appendJoinedArrays(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, char[]... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, long... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, double... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, int... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, float... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, short... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, char... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, byte... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, boolean... elements)
public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, java.lang.Object[] elements)
elements
by calling their toString method on them (or just using the String "null" for
null items), and separating each item with delimiter
. Unlike other join methods in this class, this does
not take a vararg of Object items, since that would cause confusion with the overloads that take one object, such
as join(CharSequence, Iterable)
; it takes a non-vararg Object array instead.sb
- a StringBuilder that will be modified in-placedelimiter
- the String or other CharSequence to separate items in elements withelements
- the Object items to stringify and join into one String; if the array is null or empty, this
returns an empty String, and if items are null, they are shown as "null"public static java.lang.StringBuilder appendJoined(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, java.lang.Iterable<?> elements)
elements
by calling their toString method on them (or just using the String "null" for
null items), and separating each item with delimiter
. This can take any Iterable of any type for its
elements parameter.sb
- a StringBuilder that will be modified in-placedelimiter
- the String or other CharSequence to separate items in elements withelements
- the Object items to stringify and join into one String; if Iterable is null or empty, this
returns an empty String, and if items are null, they are shown as "null"public static java.lang.StringBuilder appendJoinedAlt(java.lang.StringBuilder sb, boolean... elements)
elements
without delimiters into a String, using "1" for true and "0" for false.sb
- a StringBuilder that will be modified in-placeelements
- an array or vararg of booleanspublic static java.lang.StringBuilder appendJoinedAlt(java.lang.StringBuilder sb, java.lang.CharSequence delimiter, long... elements)
appendJoined(StringBuilder, CharSequence, long...)
, but this appends an 'L' to each number so they can be read in by Java.sb
- a StringBuilder that will be modified in-placedelimiter
- elements
- public static int count(java.lang.String source, java.lang.String search)
source
for the String search
, not scanning the same char twice except as part
of a larger String, and returns the number of instances of search that were found, or 0 if source is null or if
search is null or empty.source
- a String to look throughsearch
- a String to look forpublic static int count(java.lang.String source, int search)
source
for the codepoint search
(which is usually a char literal), not
scanning the same section twice, and returns the number of instances of search that were found, or 0 if source is
null.source
- a String to look throughsearch
- a codepoint or char to look forpublic static int count(java.lang.String source, java.lang.String search, int startIndex, int endIndex)
source
(only using the area from startIndex, inclusive, to endIndex, exclusive) for
the String search
, not scanning the same char twice except as part of a larger String, and returns the
number of instances of search that were found, or 0 if source or search is null or if the searched area is empty.
If endIndex is negative, this will search from startIndex until the end of the source.source
- a String to look throughsearch
- a String to look forstartIndex
- the first index to search through, inclusiveendIndex
- the last index to search through, exclusive; if negative this will search the rest of sourcepublic static int count(java.lang.String source, int search, int startIndex, int endIndex)
source
(only using the area from startIndex, inclusive, to endIndex, exclusive) for
the codepoint search
(which is usually a char literal), not scanning the same section twice, and returns
the number of instances of search that were found, or 0 if source is null or if the searched area is empty.
If endIndex is negative, this will search from startIndex until the end of the source.source
- a String to look throughsearch
- a codepoint or char to look forstartIndex
- the first index to search through, inclusiveendIndex
- the last index to search through, exclusive; if negative this will search the rest of sourcepublic static java.lang.String safeSubstring(java.lang.String source, int beginIndex, int endIndex)
String.substring(int, int)
but returns "" instead of throwing any sort of Exception.source
- the String to get a substring frombeginIndex
- the first index, inclusive; will be treated as 0 if negativeendIndex
- the index after the last character (exclusive); if negative this will be source.length()public static java.lang.String[] split(java.lang.String source, java.lang.String delimiter)
String.split(String)
but doesn't use any regex for splitting (delimiter is a literal String).source
- the String to get split-up substrings fromdelimiter
- the literal String to split on (not a regex); will not be included in the returned String arraypublic static java.lang.String hex(long number)
public static java.lang.String hex(double number)
public static java.lang.String hex(int number)
public static java.lang.String hex(float number)
public static java.lang.String hex(short number)
public static java.lang.String hex(char number)
public static java.lang.String hex(byte number)
public static java.lang.StringBuilder appendHex(java.lang.StringBuilder builder, long number)
public static java.lang.StringBuilder appendHex(java.lang.StringBuilder builder, double number)
public static java.lang.StringBuilder appendHex(java.lang.StringBuilder builder, int number)
public static java.lang.StringBuilder appendHex(java.lang.StringBuilder builder, float number)
public static java.lang.StringBuilder appendHex(java.lang.StringBuilder builder, short number)
public static java.lang.StringBuilder appendHex(java.lang.StringBuilder builder, char number)
public static java.lang.StringBuilder appendHex(java.lang.StringBuilder builder, byte number)
public static java.lang.String hex(long[] numbers)
public static java.lang.String hex(double[] numbers)
public static java.lang.String hex(int[] numbers)
public static java.lang.String hex(float[] numbers)
public static java.lang.String hex(short[] numbers)
public static java.lang.String hex(char[] numbers)
public static java.lang.String hex(byte[] numbers)
public static java.lang.String bin(long number)
public static java.lang.String bin(int number)
public static java.lang.String bin(short number)
public static java.lang.String bin(char number)
public static java.lang.String bin(byte number)
public static long longFromHex(java.lang.CharSequence cs)
hex(long)
method; that is, if the first char of a 16-char (or longer)
CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's
complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you
could also simply use "-1 ".
cs
- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)public static long longFromHex(java.lang.CharSequence cs, int start, int end)
hex(long)
method; that is, if the first char of a 16-char (or longer)
CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's
complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you
could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher,
such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first
(producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
cs
- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)public static long longFromHex(char[] cs, int start, int end)
hex(long)
method; that is, if the first digit of a 16-char (or longer) char[] is a hex
digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This
means "FFFFFFFFFFFFFFFF" would return the long -1L when passed to this, though you could also simply use "-1 ".
If you use both '-' at the start and have the most significant digit as 8 or higher, such as with
"-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1)
and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
cs
- a char array containing only hex digits with an optional sign (no 0x at the start)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)public static int intFromHex(java.lang.CharSequence cs)
hex(int)
method; that is, if the first digit of an 8-char (or longer) CharSequence is a hex
digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This
means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use
both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both
indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will
be multiplied by -1 to flip the sign again (returning 1).
cs
- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)public static int intFromHex(java.lang.CharSequence cs, int start, int end)
hex(int)
method; that is, if the first digit of an 8-char (or longer) CharSequence is a hex
digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This
means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use
both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both
indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will
be multiplied by -1 to flip the sign again (returning 1).
cs
- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)public static int intFromHex(char[] cs, int start, int end)
hex(int)
method; that is, if the first digit of an 8-char (or longer) char[] is a hex
digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This
means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use
both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both
indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will
be multiplied by -1 to flip the sign again (returning 1).
cs
- a char array containing only hex digits with an optional sign (no 0x at the start)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)public static long longFromDec(java.lang.CharSequence cs)
intFromDec(CharSequence)
, this can't effectively be used to read unsigned longs as decimal literals,
since anything larger than the highest signed long would be larger than the normal limit for longs as text (it
would be 20 characters without a sign, where we limit it to 19 without a sign to match normal behavior).
cs
- a CharSequence, such as a String, containing only digits 0-9 with an optional signpublic static long longFromDec(java.lang.CharSequence cs, int start, int end)
start
and end
, reading at most 19 characters (20
if there is a sign) or until end is reached and returning the result if valid, or 0 if nothing could be read. The
leading sign can be '+' or '-' if present. Unlike intFromDec(CharSequence, int, int)
, this can't
effectively be used to read unsigned longs as decimal literals, since anything larger than the highest signed
long would be larger than the normal limit for longs as text (it would be 20 characters without a sign, where we
limit it to 19 without a sign to match normal behavior).
cs
- a CharSequence, such as a String, containing only digits 0-9 with an optional signstart
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this stops after 19 or 20 characters if end is too large, depending on sign)public static int intFromDec(java.lang.CharSequence cs)
2147483647 + 2147483648
, it will interpret it as a negative number
that fits in bounds using the normal rules for converting between signed and unsigned numbers.
cs
- a CharSequence, such as a String, containing only digits 0-9 with an optional signpublic static int intFromDec(java.lang.CharSequence cs, int start, int end)
2147483647 + 2147483648
, it will interpret it as a negative number
that fits in bounds using the normal rules for converting between signed and unsigned numbers.
cs
- a CharSequence, such as a String, containing only digits 0-9 with an optional signstart
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this stops after 10 or 11 characters if end is too large, depending on sign)public static long longFromBin(java.lang.CharSequence cs)
cs
- a CharSequence, such as a String, containing only binary digits (nothing at the start)public static long longFromBin(java.lang.CharSequence cs, int start, int end)
cs
- a CharSequence, such as a String, containing only binary digits (nothing at the start)start
- the first character position in cs to read fromend
- the last character position in cs to read from (this stops after 64 characters if end is too large)public static int intFromBin(java.lang.CharSequence cs)
cs
- a CharSequence, such as a String, containing only binary digits (nothing at the start)public static int intFromBin(java.lang.CharSequence cs, int start, int end)
cs
- a CharSequence, such as a String, containing only binary digits (nothing at the start)start
- the first character position in cs to read fromend
- the last character position in cs to read from (this stops after 32 characters if end is too large)public static char[] b64Encode(long number, int offset, char[] buf)
number
- the long to encodeoffset
- the first position to set in bufbuf
- a char array that should be non-null and have length of at least offset + 11public static char[] b64Encode(double number, int offset, char[] buf)
number
- the double to encodeoffset
- the first position to set in bufbuf
- a char array that should be non-null and have length of at least offset + 11public static char[] b64Encode(int number, int offset, char[] buf)
number
- the int to encodeoffset
- the first position to set in bufbuf
- a char array that should be non-null and have length of at least offset + 6public static char[] b64Encode(float number, int offset, char[] buf)
number
- the float to encodeoffset
- the first position to set in bufbuf
- a char array that should be non-null and have length of at least offset + 6public static char[] b64Encode(short number, int offset, char[] buf)
number
- the int to encodeoffset
- the first position to set in bufbuf
- a char array that should be non-null and have length of at least offset + 3public static char[] b64Encode(char glyph, int offset, char[] buf)
glyph
- the char to encodeoffset
- the first position to set in bufbuf
- a char array that should be non-null and have length of at least offset + 3public static char[] b64Encode(byte number, int offset, char[] buf)
number
- the byte to encodeoffset
- the first position to set in bufbuf
- a char array that should be non-null and have length of at least offset + 2public static long b64DecodeLong(char[] data, int offset)
data
- a char array that should be have length of at least offset + 11offset
- where in data to start reading frompublic static double b64DecodeDouble(char[] data, int offset)
data
- a char array that should be have length of at least offset + 11offset
- where in data to start reading frompublic static int b64DecodeInt(char[] data, int offset)
data
- a char array that should be have length of at least offset + 6offset
- where in data to start reading frompublic static float b64DecodeFloat(char[] data, int offset)
data
- a char array that should be have length of at least offset + 6offset
- where in data to start reading frompublic static short b64DecodeShort(char[] data, int offset)
data
- a char array that should be have length of at least offset + 3offset
- where in data to start reading frompublic static char b64DecodeChar(char[] data, int offset)
data
- a char array that should be have length of at least offset + 3offset
- where in data to start reading frompublic static byte b64DecodeByte(char[] data, int offset)
data
- a char array that should be have length of at least offset + 2offset
- where in data to start reading frompublic static java.lang.String hexHash(boolean... array)
public static java.lang.String hexHash(byte... array)
public static java.lang.String hexHash(short... array)
public static java.lang.String hexHash(char... array)
public static java.lang.String hexHash(int... array)
public static java.lang.String hexHash(long... array)
public static java.lang.String padRight(java.lang.String text, int minimumLength)
text
- the text to pad if necessaryminimumLength
- the minimum length of String to returnpublic static java.lang.String padRight(java.lang.String text, char padChar, int minimumLength)
text
- the text to pad if necessarypadChar
- the char to use to pad text, if necessaryminimumLength
- the minimum length of String to returnpublic static java.lang.String padRightStrict(java.lang.String text, int totalLength)
text
- the String to pad if necessary, or truncate if too longtotalLength
- the exact length of String to returnpublic static java.lang.String padRightStrict(java.lang.String text, char padChar, int totalLength)
text
- the String to pad if necessary, or truncate if too longpadChar
- the char to use to fill any remaining lengthtotalLength
- the exact length of String to returnpublic static java.lang.String padLeft(java.lang.String text, int minimumLength)
text
- the text to pad if necessaryminimumLength
- the minimum length of String to returnpublic static java.lang.String padLeft(java.lang.String text, char padChar, int minimumLength)
text
- the text to pad if necessarypadChar
- the char to use to pad text, if necessaryminimumLength
- the minimum length of String to returnpublic static java.lang.String padLeftStrict(java.lang.String text, int totalLength)
text
- the String to pad if necessary, or truncate if too longtotalLength
- the exact length of String to returnpublic static java.lang.String padLeftStrict(java.lang.String text, char padChar, int totalLength)
text
- the String to pad if necessary, or truncate if too longpadChar
- the char to use to fill any remaining lengthtotalLength
- the exact length of String to returnpublic static java.util.List<java.lang.String> wrap(java.lang.CharSequence longText, int width)
"UN Secretary" "General Ban-" "Ki Moon"Spaces are not preserved if they were used to split something into two lines, but dashes are.
longText
- a probably-large piece of text that needs to be split into multiple lines with a max widthwidth
- the max width to use for any line, removing trailing whitespace at the end of a linepublic static java.util.List<java.lang.String> wrap(java.util.List<java.lang.String> receiving, java.lang.CharSequence longText, int width)
"UN Secretary" "General Ban-" "Ki Moon"Spaces are not preserved if they were used to split something into two lines, but dashes are.
receiving
- the List of String to append the word-wrapped lines tolongText
- a probably-large piece of text that needs to be split into multiple lines with a max widthwidth
- the max width to use for any line, removing trailing whitespace at the end of a linereceiving
parameter, after appending the lines from word-wrappingpublic static java.lang.String replace(java.lang.CharSequence text, java.lang.String before, java.lang.String after)
public static int indexOf(java.lang.CharSequence text, regexodus.Pattern regex, int beginIndex)
public static int indexOf(java.lang.CharSequence text, java.lang.String regex, int beginIndex)
public static int indexOf(java.lang.CharSequence text, regexodus.Pattern regex)
public static int indexOf(java.lang.CharSequence text, java.lang.String regex)
public static java.lang.String capitalize(java.lang.CharSequence original)
original
, Returning A New String.original
- a CharSequence, such as a StringBuilder or String, which could have CrAzY capitalizationpublic static java.lang.String sentenceCase(java.lang.CharSequence original)
original
, capitalizes the first letter of each sentence, and otherwise
leaves the CharSequence untouched as it returns it as a String. Sentences are detected with a crude heuristic of
"does it have periods, exclamation marks, or question marks at the end, or does it reach the end of input? If
yes, it's a sentence."original
- a CharSequence that is expected to contain sentence-like data that needs capitalization; existing upper-case letters will stay upper-case.public static java.lang.String correctABeforeVowel(java.lang.CharSequence text)
text
- the (probably generated English) multi-word text to search for 'a' in and possibly replace with 'an'Copyright © Eben Howard 2012–2022. All rights reserved.