Package gnu.lists
Class Strings
- java.lang.Object
-
- gnu.lists.Strings
-
public class Strings extends Object
Various static utility methods for general strings (CharSeqs).
-
-
Constructor Summary
Constructors Constructor Description Strings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
characterAt(CharSequence cseq, int index)
Get character (code point) at a offset.static int
characterAt(CharSequence cseq, int start, int end, int index)
Get character (code point) at a offset.static int
compareTo(CharSequence str1, CharSequence str2)
static void
copyInto(CharSequence src, int start, int end, CharSeq dst, int at)
static String
fromUtf8(byte[] bytes, int start, int length)
static int
indexByCodePoints(CharSequence str, int index)
Get index'th character (code point).static IString
indirectIndexed(CharSequence base, IntSequence indexes)
Make a read-only substring, generalized to arbitrary index sequences.static void
makeCapitalize(CharSeq str)
Capitalize this string.static void
makeLowerCase(CharSeq str)
Change every character to be lowercase.static void
makeUpperCase(CharSeq str)
Change every character to be uppercase.static int
offsetByCodePoints(CharSequence str, int offset, int cuStart, int cpStart)
Like offsetByCodePoints, but optimize if an IString.static void
printJson(CharSequence str, Appendable ps)
static void
printQuoted(CharSequence str, Appendable ps, int escapes)
Print a string with quotes and escapes.static String
replicate(int from, int to, boolean suppliedTo, CharSequence string, int start, int end, boolean suppliedEnd)
static int
sizeInCodePoints(CharSequence str)
static CharSequence
substring(CharSequence base, int start, int end)
Make a read-only substring.static String
toJson(CharSequence str)
static byte[]
toUtf16(CharSequence str, int start, int end, boolean bigEndian, boolean writeBOM)
-
-
-
Method Detail
-
characterAt
public static int characterAt(CharSequence cseq, int index)
Get character (code point) at a offset.- Parameters:
index
- offset measured in 16-bit code units
-
characterAt
public static int characterAt(CharSequence cseq, int start, int end, int index)
Get character (code point) at a offset.- Parameters:
index
- offset measured in 16-bit code units, from begining of cseq, not frm start
-
indexByCodePoints
public static int indexByCodePoints(CharSequence str, int index)
Get index'th character (code point).- Parameters:
index
- offset by code points
-
offsetByCodePoints
public static int offsetByCodePoints(CharSequence str, int offset, int cuStart, int cpStart)
Like offsetByCodePoints, but optimize if an IString.- Parameters:
offset
- number of code points beyond start index.cuStart
- start index in code units (Java chars)cpStart
- start index in Unicode code points
-
sizeInCodePoints
public static int sizeInCodePoints(CharSequence str)
-
makeUpperCase
public static void makeUpperCase(CharSeq str)
Change every character to be uppercase.
-
makeLowerCase
public static void makeLowerCase(CharSeq str)
Change every character to be lowercase.
-
makeCapitalize
public static void makeCapitalize(CharSeq str)
Capitalize this string. Change first character of each word to titlecase, and change the other characters to lowercase.
-
toJson
public static String toJson(CharSequence str)
-
printJson
public static void printJson(CharSequence str, Appendable ps)
-
printQuoted
public static void printQuoted(CharSequence str, Appendable ps, int escapes)
Print a string with quotes and escapes.- Parameters:
escapes
- The value 0 means only escape '"' and '\\'; the value 1 means escape standard escape characters like '\\b'; the value 2 means escape all non-ascii or control characters; the value 3 means follow the JSON standard.
-
copyInto
public static void copyInto(CharSequence src, int start, int end, CharSeq dst, int at)
-
indirectIndexed
public static IString indirectIndexed(CharSequence base, IntSequence indexes)
Make a read-only substring, generalized to arbitrary index sequences. The indexes are in terms of code points (character) offsets.
-
substring
public static CharSequence substring(CharSequence base, int start, int end)
Make a read-only substring. The start and end are in terms of code unit (16-bit char).
-
fromUtf8
public static String fromUtf8(byte[] bytes, int start, int length)
-
toUtf16
public static byte[] toUtf16(CharSequence str, int start, int end, boolean bigEndian, boolean writeBOM)
-
compareTo
public static int compareTo(CharSequence str1, CharSequence str2)
-
replicate
public static String replicate(int from, int to, boolean suppliedTo, CharSequence string, int start, int end, boolean suppliedEnd)
-
-