Package jexer.bits
Class StringUtils
- java.lang.Object
-
- jexer.bits.StringUtils
-
public class StringUtils extends java.lang.Object
StringUtils 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 boolean
isBraille(int ch)
Check if character is in the braille range.static boolean
isCjk(int ch)
Check if character is in the CJK range.static boolean
isEmoji(int ch)
Check if character is in the emoji range.static boolean
isLegacyComputingSymbol(int ch)
Check if character is in the Symbols for Legacy Computing range.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.String
toBase64(byte[] sArr)
Encodes a raw byte array into a BASE64byte[]
representation i accordance with RFC 2045.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).static java.lang.String
unescape(java.lang.String str)
Convert raw strings into escaped strings that be splatted on the screen.static int
width(int ch)
Determine display width of a Unicode code point.static int
width(java.lang.String str)
Determine display width of a string.
-
-
-
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
-
isCjk
public static boolean isCjk(int ch)
Check if character is in the CJK range.- Parameters:
ch
- character to check- Returns:
- true if this character is in the CJK range
-
isEmoji
public static boolean isEmoji(int ch)
Check if character is in the emoji range.- Parameters:
ch
- character to check- Returns:
- true if this character is in the emoji range
-
isLegacyComputingSymbol
public static boolean isLegacyComputingSymbol(int ch)
Check if character is in the Symbols for Legacy Computing range.- Parameters:
ch
- character to check- Returns:
- true if this character is in the Symbols for Legacy Computing range
-
isBraille
public static boolean isBraille(int ch)
Check if character is in the braille range.- Parameters:
ch
- character to check- Returns:
- true if this character is in the braille range
-
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. Ifnull
or 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.null
will throw an exception.- Returns:
- The decoded array of bytes. May be of length 0. Will be
null
if the legal characters (including '=') isn't divideable by 4. (I.e. definitely corrupted).
-
-