public class TextBreaker
extends java.lang.Object
This class is particularly useful for preparing text for display in user interfaces, reports, (log) files, or any scenario where controlled text wrapping and formatting are required.
TODO: This class is currently named `TextBreaker`, but its functionality extends beyond simply breaking text. It acts more as a TextFormatter or LineWrapper, handling various aspects of text presentation such as configurable line lengths, prefixes, postfixes, word splitting (even for words longer than the line), and tag-aware text processing. A more descriptive name would better reflect its comprehensive text formatting capabilities.
Constructor and Description |
---|
TextBreaker(int _lineLength,
java.lang.String _linePrefix,
java.lang.String _linePostfix)
Constructs a new TextBreaker instance with specified line length, prefix, and postfix applied uniformly to all lines.
|
Modifier and Type | Method and Description |
---|---|
void |
appendIfNotNull(java.lang.StringBuilder sb,
java.lang.String s)
Appends a string to a StringBuilder only if the string is not null.
|
java.lang.String |
breakText(java.lang.String s)
Breaks and formats the given string into multiple lines according to the
configured line lengths, prefixes, and postfixes.
|
java.lang.String |
breakText(java.lang.String s,
boolean breakOnAnyWhiteSpaceChar) |
int |
getFirstLineLength() |
java.lang.String |
getFirstLinePostfix() |
java.lang.String |
getFirstLinePrefix() |
java.lang.String |
getLengthForLine(int n)
Returns the desired line length for a given line number.
|
int |
getLineLength() |
java.lang.String |
getLinePostfix() |
java.lang.String |
getLinePostfixForLine(int n)
Returns the line postfix for a given line number.
|
java.lang.String |
getLinePrefix() |
java.lang.String |
getLinePrefixForLine(int n)
Returns the line prefix for a given line number.
|
java.lang.String |
getNewParagraphChar() |
java.lang.String |
getWhitespaceChars() |
boolean |
isSplitWordsLongerThanLine() |
int |
longestSubWord(netrexx.lang.Rexx s,
int w,
netrexx.lang.Rexx line)
Gets a long word "s", e.g. trichotillomania (an abnormal desire to pull out one's hair -
might explain the baldness of some programmers ;)) and specifies the substring position
of the "whitespaceChars" separator, where you have to cut the word at the latest for it
to be no longer than w.
|
void |
setFirstLineLength(int $19) |
void |
setFirstLinePostfix(java.lang.String $17) |
void |
setFirstLinePrefix(java.lang.String $15) |
void |
setLineLength(int $20) |
void |
setLinePostfix(java.lang.String $18) |
void |
setLinePrefix(java.lang.String $16) |
void |
setNewParagraphChar(java.lang.String $22) |
void |
setSplitWordsLongerThanLine(boolean $23) |
void |
setWhitespaceChars(java.lang.String $21) |
public TextBreaker(int _lineLength, java.lang.String _linePrefix, java.lang.String _linePostfix)
_lineLength
- The maximum length for all lines. A value of -1 means no line breaking._linePrefix
- The prefix to be prepended to all lines._linePostfix
- The postfix to be appended to all lines.public java.lang.String breakText(java.lang.String s)
s
- The input string to be formatted.breakOnAnyWhiteSpaceChar
- A boolean flag indicating whether to attempt to break words at any character specified
in "whitespaceChars" when a word is too long for the current line.public java.lang.String breakText(java.lang.String s, boolean breakOnAnyWhiteSpaceChar)
public void appendIfNotNull(java.lang.StringBuilder sb, java.lang.String s)
sb
- The StringBuilder to append to.s
- The string to append.public java.lang.String getLengthForLine(int n)
n
- The current line number (1-indexed).public java.lang.String getLinePrefixForLine(int n)
n
- The current line number (1-indexed).public java.lang.String getLinePostfixForLine(int n)
n
- The current line number (1-indexed).public int longestSubWord(netrexx.lang.Rexx s, int w, netrexx.lang.Rexx line)
s
- The long word to potentially break.w
- The maximum remaining width available for the word.line
- The current line content, including the word, used for tag-aware processing.public java.lang.String getFirstLinePrefix()
public void setFirstLinePrefix(java.lang.String $15)
public java.lang.String getLinePrefix()
public void setLinePrefix(java.lang.String $16)
public java.lang.String getFirstLinePostfix()
public void setFirstLinePostfix(java.lang.String $17)
public java.lang.String getLinePostfix()
public void setLinePostfix(java.lang.String $18)
public int getFirstLineLength()
public void setFirstLineLength(int $19)
public int getLineLength()
public void setLineLength(int $20)
public java.lang.String getWhitespaceChars()
public void setWhitespaceChars(java.lang.String $21)
public java.lang.String getNewParagraphChar()
public void setNewParagraphChar(java.lang.String $22)
public boolean isSplitWordsLongerThanLine()
public void setSplitWordsLongerThanLine(boolean $23)
Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.