public class StringTools
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
leftIndent(java.lang.String input,
int leftIndent)
Takes an input string and appends spaces to the left.
|
static java.lang.String |
leftPad(java.lang.String input,
char padChar,
int totalWidth)
Pads a string to be a certain width by prepending given symbols.
|
static java.lang.String |
leftPad(java.lang.String input,
int totalWidth)
Pads a string to be a certain width by prepending spaces.
|
static java.lang.String |
rightPad(java.lang.String input,
char padChar,
int totalWidth)
Pads a string to be a certain width by appending given symbols.
|
static java.lang.String |
rightPad(java.lang.String input,
int totalWidth)
Pads a string to be a certain width by appending spaces.
|
static java.lang.String[] |
wordWrap(java.lang.String input,
java.lang.String sepRegex,
int width)
Word-wraps a string into an array of lines of no more than the given width.
|
static void |
writeKeyValueLine(java.lang.String key,
java.lang.String text,
int keyWidth,
int lineWidth,
java.io.PrintStream os)
Writes some text to the output stream in the following format:
key text
continuation of text
where the key/wrappedKey column is keyWidth wide, and the total line width is lineWidth,
and the text is split over multiple lines at the nearest occurrence of whitespace.
|
static void |
writeKeyValueLine(java.lang.String key,
java.lang.String text,
int keyWidth,
int lineWidth,
java.lang.String sep,
java.io.PrintStream os)
Writes some text to the output stream in the following format:
key text
continuation of text
where the key/wrappedKey column is keyWidth wide, and the total line width is lineWidth,
and the text is split over multiple lines at the nearest occurrence of separator sep.
|
static void |
writeKeyValueLine(java.lang.String key,
java.lang.String text,
int keyWidth,
int lineWidth,
java.lang.String sep,
java.lang.String wrappedKey,
java.io.PrintStream os)
Writes some text to the output stream in the following format:
key text
wrappedKey continuation of text
where the key/wrappedKey column is keyWidth wide, and the total line width is lineWidth,
and the text is split over multiple lines at the nearest occurrence of separator sep.
|
public static java.lang.String leftIndent(java.lang.String input, int leftIndent)
input
- the input stringleftIndent
- the number of spaces to indent it by.public static java.lang.String leftPad(java.lang.String input, int totalWidth)
input
- the string to pad.totalWidth
- the final width required including padded space.public static java.lang.String leftPad(java.lang.String input, char padChar, int totalWidth)
input
- the string to pad.padChar
- the symbol to pad with.totalWidth
- the final width required including padded symbols.public static java.lang.String rightPad(java.lang.String input, int totalWidth)
input
- the string to pad.totalWidth
- the final width required including padded space.public static java.lang.String rightPad(java.lang.String input, char padChar, int totalWidth)
input
- the string to pad.padChar
- the symbol to pad with.totalWidth
- the final width required including padded symbols.public static java.lang.String[] wordWrap(java.lang.String input, java.lang.String sepRegex, int width)
input
- the string to formatsepRegex
- the regex identifying the break points in the string, to be
compiled using Pattern.width
- the width of the lines requiredPattern
public static void writeKeyValueLine(java.lang.String key, java.lang.String text, int keyWidth, int lineWidth, java.io.PrintStream os)
key
- the key to write on the first line onlytext
- the text to write outkeyWidth
- the width to indent the text by (in which the key will be printed)os
- the stream to write the formatted output topublic static void writeKeyValueLine(java.lang.String key, java.lang.String text, int keyWidth, int lineWidth, java.lang.String sep, java.io.PrintStream os)
key
- the key to write on the first line onlytext
- the text to write outkeyWidth
- the width to indent the text by (in which the key will be printed)sep
- the separator to split the text on if it exceeds the line widthos
- the stream to write the formatted output topublic static void writeKeyValueLine(java.lang.String key, java.lang.String text, int keyWidth, int lineWidth, java.lang.String sep, java.lang.String wrappedKey, java.io.PrintStream os)
key
- the key to write on the first line onlytext
- the text to write outkeyWidth
- the width to indent the text by (in which the key will be printed)sep
- the separator to split the text on if it exceeds the line widthwrappedKey
- the key to print on second and subsequent linesos
- the stream to write the formatted output to