Package jexer.bits
Class StringUtils
- java.lang.Object
-
- jexer.bits.StringUtils
-
public class StringUtils extends java.lang.ObjectStringUtils contains methods to: - Convert one or more long lines of strings into justified text paragraphs. - Unescape C0 control codes. - Read/write a line of RFC4180 comma-separated values strings to/from a list of strings. - Compute number of visible text cells for a given Unicode codepoint or string. - Convert bytes to and from base-64 encoding.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.lang.String>center(java.lang.String str, int n)Center a string into a list of lines.static byte[]fromBase64(byte[] sArr)Decodes a BASE64 encoded byte array.static java.util.List<java.lang.String>fromCsv(java.lang.String line)Read a line of RFC4180 comma-separated values (CSV) into a list of strings.static java.util.List<java.lang.String>full(java.lang.String str, int n)Fully-justify a string into a list of lines.static java.util.List<java.lang.String>left(java.lang.String str, int n)Left-justify a string into a list of lines.static java.util.List<java.lang.String>right(java.lang.String str, int n)Right-justify a string into a list of lines.static java.lang.StringtoBase64(byte[] sArr)Encodes a raw byte array into a BASE64byte[]representation i accordance with RFC 2045.static int[]toCodePoints(java.lang.String input)Converts a string into an array of Unicode codepoints.static java.util.List<ComplexCell>toComplexCells(java.lang.String input)Converts a string into a sequence of grapheme clusters following most of the rules of Unicode TR #29 section 3.1.1.static java.lang.StringtoCsv(java.util.List<java.lang.String> list)Write a list of strings to on line of RFC4180 comma-separated values (CSV).static java.lang.Stringunescape(java.lang.String str)Convert raw strings into escaped strings that be splatted on the screen.static intwidth(int ch)Determine display width of a Unicode code point.static intwidth(int[] codePoints)Determine display width of an array of codepoints that will be displayed as a single extended grapheme cluster.static intwidth(java.lang.String str)Determine display width of a string.static intwidth(java.util.List<java.lang.Integer> codePoints)Determine display width of a list of codepoints that will be displayed as a single extended grapheme cluster.static intwidth(Cell cell)Determine display width of a Cell that will be displayed as a single extended grapheme cluster.
-
-
-
Method Detail
-
left
public static java.util.List<java.lang.String> left(java.lang.String str, int n)Left-justify a string into a list of lines.- Parameters:
str- the stringn- the maximum number of characters in a line- Returns:
- the list of lines
-
right
public static java.util.List<java.lang.String> right(java.lang.String str, int n)Right-justify a string into a list of lines.- Parameters:
str- the stringn- the maximum number of characters in a line- Returns:
- the list of lines
-
center
public static java.util.List<java.lang.String> center(java.lang.String str, int n)Center a string into a list of lines.- Parameters:
str- the stringn- the maximum number of characters in a line- Returns:
- the list of lines
-
full
public static java.util.List<java.lang.String> full(java.lang.String str, int n)Fully-justify a string into a list of lines.- Parameters:
str- the stringn- the maximum number of characters in a line- Returns:
- the list of lines
-
unescape
public static java.lang.String unescape(java.lang.String str)
Convert raw strings into escaped strings that be splatted on the screen.- Parameters:
str- the string- Returns:
- a string that can be passed into Screen.putStringXY()
-
fromCsv
public static java.util.List<java.lang.String> fromCsv(java.lang.String line)
Read a line of RFC4180 comma-separated values (CSV) into a list of strings.- Parameters:
line- the CSV line, with or without without line terminators- Returns:
- the list of strings
-
toCsv
public static java.lang.String toCsv(java.util.List<java.lang.String> list)
Write a list of strings to on line of RFC4180 comma-separated values (CSV).- Parameters:
list- the list of strings- Returns:
- the CSV line, without any line terminators
-
width
public static int width(int ch)
Determine display width of a Unicode code point.- Parameters:
ch- the code point, can be char- Returns:
- the number of text cell columns required to display this code point, one of 0, 1, or 2
-
width
public static int width(java.lang.String str)
Determine display width of a string. This ASSUMES that no characters are combining. Hopefully no users will be impacted.- Parameters:
str- the string- Returns:
- the number of text cell columns required to display this string
-
width
public static int width(java.util.List<java.lang.Integer> codePoints)
Determine display width of a list of codepoints that will be displayed as a single extended grapheme cluster.- Parameters:
codePoints- the codepoints- Returns:
- the number of text cell columns required to display this grapheme, either 1 or 2
-
width
public static int width(int[] codePoints)
Determine display width of an array of codepoints that will be displayed as a single extended grapheme cluster.- Parameters:
codePoints- the codepoints- Returns:
- the number of text cell columns required to display this grapheme, either 1 or 2
-
width
public static int width(Cell cell)
Determine display width of a Cell that will be displayed as a single extended grapheme cluster.- Parameters:
cell- the cell- Returns:
- the number of text cell columns required to display this grapheme, either 1 or 2
-
toCodePoints
public static int[] toCodePoints(java.lang.String input)
Converts a string into an array of Unicode codepoints.- Parameters:
input- a string of codepoints- Returns:
- an array of codepoints
-
toComplexCells
public static java.util.List<ComplexCell> toComplexCells(java.lang.String input)
Converts a string into a sequence of grapheme clusters following most of the rules of Unicode TR #29 section 3.1.1.- Parameters:
input- a string of codepoints- Returns:
- a sequence of grapheme clusters
-
toBase64
public static final java.lang.String toBase64(byte[] sArr)
Encodes a raw byte array into a BASE64byte[]representation i accordance with RFC 2045.- Parameters:
sArr- The bytes to convert. Ifnullor length 0 an empty array will be returned.- Returns:
- A BASE64 encoded array. Never
null.
-
fromBase64
public static final byte[] fromBase64(byte[] sArr)
Decodes a BASE64 encoded byte array. All illegal characters will be ignored and can handle both arrays with and without line separators.- Parameters:
sArr- The source array. Length 0 will return an empty array.nullwill throw an exception.- Returns:
- The decoded array of bytes. May be of length 0. Will be
nullif the legal characters (including '=') isn't divideable by 4. (I.e. definitely corrupted).
-
-