@MinDoc(copyright="Copyright 2000 - 2013, 2021 A. Weinert", author="Albrecht Weinert", version="V.65", lastModified="3.06.2024", usage="import", purpose="common text utilities: check, parse and formating of texts") public abstract class TextHelper extends Object
String, as among others RK, PropMap| Modifier and Type | Class and Description |
|---|---|
static interface |
TextHelper.MessageComponents
Deliverer of messageFormat components.
|
static interface |
TextHelper.ReplaceVisitor
Visitor for text replacements.
|
| Modifier and Type | Field and Description |
|---|---|
static Exception |
lastFormatingExc
The last exception when formatting.
|
| Modifier and Type | Method and Description |
|---|---|
static Appendable |
append(Appendable dest,
byte[] bA)
Byte array as separated sequence of two digit hex numbers.
|
static Appendable |
append(Appendable dest,
byte[] bA,
int off,
int len)
Part of byte array as separated sequence of two digit hex numbers.
|
static boolean |
areEqual(CharSequence s1,
CharSequence s2,
boolean ignCase)
Compare two character sequences, optionally ignoring case.
|
static boolean |
asBoolean(CharSequence value)
Interpret a character sequence as boolean.
|
static boolean |
asBoolean(CharSequence value,
boolean def)
Interpret a character sequence as Boolean.
|
static Boolean |
asBoolObj(CharSequence value)
Interpret a character sequence as Boolean.
|
static Boolean |
asBoolObj(Object value)
Interpret an Object as Boolean.
|
static int |
asInt(CharSequence value,
int def)
Interpret a character sequence as int with default value.
|
static Integer |
asIntObj(CharSequence value)
Interpret a character sequence as Integer.
|
static String |
checkLanguage(CharSequence language,
CharSequence defValue)
Check and correct language code.
|
static boolean |
checkMac(StringBuilder leMac)
Check (quite rawly) the syntax and uniform a MAC address.
|
static String |
checkMail(CharSequence adr,
CharSequence defaultServer,
boolean forceServer)
Check / complete an e-Mail address.
|
static String |
checkRegion(CharSequence region,
CharSequence defValue)
Check and correct region code.
|
static int |
compare(CharSequence s1,
CharSequence s2,
boolean ignCase)
A String compare optionally (optimised) ignoring case.
|
static String |
con3cat(CharSequence s1,
CharSequence s2,
CharSequence s3)
Concatenate three Strings.
|
static int |
countParams(String[] args)
Count of non empty Strings or arguments in a (parameter) array.
|
static char |
dig(int value)
A decimal digit as char.
|
static Appendable |
eightDigitHex(Appendable dest,
int value)
Format as eight digit hexadecimal number.
|
static boolean |
endsWith(CharSequence st1,
CharSequence st2,
boolean ignoreCase)
Determine if a character sequence ends with another one.
|
static int |
equalsTil(CharSequence[] sequences,
boolean ignoreCase)
Index of first mismatch optionally ignoring case.
|
static int |
equalsTil(CharSequence sequ,
int sI,
CharSequence seq2,
boolean ignoreCase)
Index of first mismatch optionally ignoring case.
|
static Appendable |
format(Appendable dest,
CharSequence name,
CharSequence[] sA,
int sLen)
Format a String array.
|
static StringBuilder |
formatDuration(StringBuilder dest,
long dur)
Formatting a runtime or period (long ms) as text.
|
static Appendable |
formDec(Appendable dest,
int value,
int width)
Format decimal number right justified .
|
static Appendable |
fourDigitHex(Appendable dest,
int value)
Format as four digit hexadecimal number.
|
static int |
fUr(CharSequence source,
StringBuilder dest,
CharSequence oldText,
CharSequence newText,
boolean ignoreCase)
Find and Replace a character sequence's parts (multiply).
|
static int |
fUr(CharSequence source,
StringBuilder dest,
CharSequence oldStart,
CharSequence oldEnd,
CharSequence newText,
boolean ignoreCase)
Find and Replace character sequence's parts (multiply).
|
static int |
fUr(CharSequence source,
StringBuilder dest,
CleverSSS oldStart,
CleverSSS oldEnd,
String newText,
boolean ckWd)
Find and Replace character sequence's parts (multiple, String).
|
static int |
fUr(CharSequence quell,
StringBuilder dest,
CleverSSS oldStart,
CleverSSS oldEnd,
TextHelper.ReplaceVisitor repl)
Find and Replace character sequence's parts (multiple as visitor).
|
static int |
fUr(CharSequence quell,
StringBuilder ziel,
String oldStart,
String oldEnd,
boolean ignoreCase,
TextHelper.ReplaceVisitor repl)
Find and Replace character sequence's parts (multiple as visitor).
|
static Pattern |
getCommaSemicolonWSpattern()
Pattern for separation at comma, semicolon or white space.
|
static String |
getPropertyText(CharSequence text,
CharSequence default1,
String default2)
Select (property-) text from different choices.
|
static String |
getPropertyText(CharSequence text,
String def)
Select (property-) text from different choices — simple trim.
|
static int |
indexOf(CharSequence sequ,
CharSequence sub,
int sI,
boolean ignoreCase)
An "indexOf" ignoring case.
|
static int |
indexOf(String text,
String[] list)
Search a character sequence in a list / array.
|
static int |
indexOfOpt(CharSequence sequ,
CharSequence sub,
int sI,
boolean ignoreCase)
An optimistic "indexOf" optionally ignoring case.
|
static int |
isFrntMttr(CharSequence txt)
Check if a text starts with a Jekyll front matter.
|
static int |
lastIndexOf(CharSequence sequ,
CharSequence sub)
A lastIndexOf ignoring case.
|
static int |
lastIndexOf(CharSequence sequ,
CharSequence sub,
int sI)
A lastIndexOf ignoring case.
|
static int |
lastIndexOf(CharSequence sequ,
CharSequence sub,
int sI,
boolean ignoreCase)
A lastIndexOf optionally ignoring case.
|
static int |
lastIndexOfWS(CharSequence sequ,
int sI)
A white space searching lastIndexOf.
|
static String |
makeFName(CharSequence name,
String ext)
Construct a file name.
|
static String |
makeFNameUJ(CharSequence name)
Construct a file name for URLs or .jar entries.
|
static String |
makeFNL(String path)
Working up names of files or of file name lists.
|
static TextHelper.MessageComponents |
makeMessageComponents(Object[] oa)
Make MessageComponents from an array.
|
static StringBuilder |
messageFormat(StringBuilder dest,
CharSequence pattern,
Object args)
A simple message formatter.
|
static String[] |
prepParams(CharSequence argLine,
int endArg)
Make a parameter array from a character sequence (command line).
|
static String[] |
prepParams(CharSequence argLine,
String commSt,
boolean unQuote)
Make a parameter array from a character sequence (command line).
|
static String |
prepParams(String[] args)
Make an argument line from a parameter array.
|
static String[] |
prepParams(String[] args,
String commSt,
boolean unQuote)
Working up of parameter arrays.
|
static boolean |
shouldQuote(CharSequence akt)
Make a recommendation about quoting argument.
|
static boolean |
simpCharEqu(char c1,
char c2,
boolean ignCase)
Character equals optionally ignoring case.
|
static Appendable |
sixDigitHex(Appendable dest,
int value)
Format as six digit hexadecimal number.
|
static String[] |
splitCsWS(CharSequence input)
Separating at comma, semicolon or white space.
|
static String[] |
splitWords(String origContent)
Split a String to single words.
|
static boolean |
startsWith(CharSequence st1,
CharSequence st2,
boolean ignoreCase)
Determine if a character sequence begins with another one.
|
static String |
threeDigit(int value)
Format as three digit number with leading zeros.
|
static String |
trimUq(CharSequence val,
String def)
Trim and "un-quote" a character sequence.
|
static String |
twoDigit(int value)
Format as two digit number with leading zero.
|
static Appendable |
twoDigitDec(Appendable dest,
int value)
Format as two digit decimal number with leading zero.
|
static Appendable |
twoDigitHex(Appendable dest,
int value)
Format as two digit hexadecimal number.
|
static String |
twoDigitHex(int value)
Format as two digit hexadecimal number.
|
static String |
unComment(String s,
char stC,
char endC,
boolean nested,
CharSequence repl)
Remove bracketed comments, optionally nested.
|
static boolean |
wildEqual(CharSequence wildName,
CharSequence name,
boolean ignoreCase)
Compare a name and a pattern with wildcards.
|
static void |
write(PrintWriter out,
CharSequence name,
CharSequence[] sA)
Output a String array.
|
static char |
zif(int value)
A hexadecimal digit as char.
|
public static Exception lastFormatingExc
Appendable object is not a supplied or
generated StringBuilder but e.g. a PrintWriter
IOExceptions may occur. They are caught silently in the
formatting method but recorded here.public static String con3cat(CharSequence s1, CharSequence s2, CharSequence s3)
s1 + s2 + s3 as far as not null or empty in each case.ComVar.EMPTY_STRING)
is returned.(s1 + s2 +..).public static String getPropertyText(CharSequence text, CharSequence default1, String default2)
text is freed / stripped of all surrounding white spaces. If
(then) not empty, it is returned.default1. Does that
also give no non empty value, default2 is returned as is.public static String getPropertyText(CharSequence text, String def)
text is freed / stripped of all surrounding white spaces. If
(then) not empty, it is returned. Otherwise default2 is returned as
is.trimUq(text, default2) is this
method having no "un-quote"; see
there. The differences to
String.trim() are the acceptance of any
CharSequence and the default value.
String.trim() behaviour is got by
supplying ComVar.EMPTY_STRING as
def.public static String makeFName(CharSequence name, String ext)
name and ext or it returns null.name will be stripped from surrounding white space. If then empty
null will be returned.ComVar.FS).
If ext is not null or empty (after stripping white spaces) it will
be prefixed by a dot (.) if does not yet start so.ext will be appended to the name if that
is not yet ending so (disregarding case).name - file name demandedext - default extension (appended if not yet name's end)public static String makeFNameUJ(CharSequence name)
name or null.name will be stripped from surrounding white space. If then empty
null will be returned.name - file or entry namepublic static String makeFNL(String path)
path or null. path will be stripped from surrounding
white space. If then empty null will be returned.ComVar.FS).public static int isFrntMttr(CharSequence txt)
"---". txt.txt starts with such front matter this function
returns the index of the first character after the terminating second
line "---\r\n" or "---\n". txt - the text to be checkedpublic static boolean simpCharEqu(char c1,
char c2,
boolean ignCase)
public static boolean endsWith(CharSequence st1, CharSequence st2, boolean ignoreCase)
st1 ends with
the sequence st2, disregarding case if ignoreCase is
true.st1 is null or empty.st2 is null or empty.st1 - the sequence which's end is tested to be st2st2 - the sequence to be matched to the end of st1ignoreCase - if true the comparison is not case sensitivesimpCharEqu(char, char, boolean)public static boolean startsWith(CharSequence st1, CharSequence st2, boolean ignoreCase)
st1 begins with
the sequence st2, disregarding case if ignoreCase is
true.st1 is null or empty.st2 is null or empty.public static boolean asBoolean(CharSequence value)
value is
"true", "wahr", "ja", "yes", "an" or "on"
disregarding case.public static Boolean asBoolObj(Object value)
Boolean as is and delegates
CharSequences to the method
asBoolObj(CharSequence).asBoolObj(CharSequence)public static Boolean asBoolObj(CharSequence value)
Boolean.TRUE, if the sequence value is
"true", "wahr", "ja", "yes", "an" or "on"
disregarding case.Boolean.FALSE, if the sequence value is
"fals?", "fals??", (including thus "false" and "falsch"), "ne??",
"nein", "no", "aus" or "off" (? means any character) ,
also disregarding case.public static boolean asBoolean(CharSequence value, boolean def)
value is
"true", "wahr", "ja", "yes", "an" or "on"
disregarding case.value is
"fals?", "fals??", "false", "falsch", "ne??", "nein",
"no", "aus" or "off" (? means any character).def is returned.asBoolean
respectively asBoolObj methods this is
the most efficient (fastest) as the parsing is steered (shortened) by the
default value supplied.public static Integer asIntObj(CharSequence value)
value will be stripped from surrounding white space and perhaps
enclosing quotes. If value is (then) empty (Integer)null will be
returned.Integer object wrapping the number is
returned and null in case of the no interpretation succeeded.Integer.decode(java.lang.String).value - the sequence to be interpreted as whole numbertrimUq(CharSequence, String)public static int asInt(CharSequence value, int def)
value will be stripped from surrounding white space and perhaps
enclosing quotes. If value is (then) empty def will be
returned.value - the sequence to be interpreted as whole numberdef - the substitute valuetrimUq(CharSequence, String),
asIntObj(CharSequence)public static int compare(CharSequence s1, CharSequence s2, boolean ignCase)
s1 - the first String to be compareds2 - the second String to be comparedignCase - true: compare ignore caseareEqual(CharSequence, CharSequence, boolean)public static String trimUq(CharSequence val, String def)
val null or empty the substitute
def is returned. Usual choices for the default value
def are null or the empty String
(ComVar.EMPTY_STRING).val will be stripped from
leading and trailing white spaces (spaces, tabulators, feeds). If then
empty, the substitute def is returned.val is returned as
String, if it not begins and ends with double quotes (").val - the character sequence to considerdef - substitute value for null or empty or white space onlygetPropertyText(CharSequence, String),
getPropertyText(CharSequence, CharSequence, String)public static boolean areEqual(CharSequence s1, CharSequence s2, boolean ignCase)
public static boolean wildEqual(CharSequence wildName, CharSequence name, boolean ignoreCase)
name to a pattern
wildName, that may contain the wildcard characters ? and *
(question mark and asterisk / starlet).name and wildName are considered as as equal if the
characters coincide, applying the extra rules for characters in
wildName:name.name of any
length including 0.wildName is followed by another character the
"sequence of any length" in name (the coincidence) ends
at the first occurrence of that character. From then on the comparing
goes on as described.name 1234.567.890 would fit the pattern wildNamewildName - the pattern to match; included wildcards (* ?) are
interpreted as described. In case of null or empty true is
returned.name - the name to match / compare. If name is null or empty (and
wildName not so) false is returned.ignoreCase - if true the comparison is not case sensitivepublic static int fUr(CharSequence source, StringBuilder dest, CharSequence oldText, CharSequence newText, boolean ignoreCase)
source will be appended to the
StringBuilder dest. Hereby any sequence oldText (out of
source} will be be replaced by newText (while transferring into
dest). If ignoreCase is true, the sequences
oldText are searched for disregarding case.dest is not touched.dest if no
replacements — is unwanted on has to do
dest.append(source) on return of 0.fUr(source, dest, oldText, null, newText, ignoreCase)public static int fUr(CharSequence source, StringBuilder dest, CharSequence oldStart, CharSequence oldEnd, CharSequence newText, boolean ignoreCase)
fUr()
except for the following extra: There is not just one pattern for the
source's sequence to be replaced but a bracket of to pattern
oldStart and oldEnd that might enclose arbitrary other
text to be replaced by newText.
ignoreCase would apply to both oldStart and oldEnd.
If oldEnd is null only oldStart is searched for in
source.fUr(CharSequence, StringBuilder, CleverSSS, CleverSSS, ReplaceVisitor)public static int fUr(CharSequence quell, StringBuilder ziel, String oldStart, String oldEnd, boolean ignoreCase, TextHelper.ReplaceVisitor repl)
source will be appended to the
StringBuilder dest. Hereby any sequence in source
consisting ofoldStart, any sequence and oldEndignoreCase is true the character comparison is made
disregarding case.repl.visit() is called with those three
sequences as parameters. In the case of ignoreCase true the
found brackets are supplied and not oldStart and oldEnd
which might differ in case. The value returned by the
TextHelper.ReplaceVisitor's method
visit() will be put to dest instead
of that "block of three". If null is returned by the visitor
that spot will be transfered unchanged and this will not be counted
as replacement.source was transferred unmodified to the
StringBuilder dest.oldEnd is null only oldStart is searched for in
source and the TextHelper.ReplaceVisitor's method
visit() will be called so
visit(null, oldStart, null). To be exact:
in the case of ignoreCase true the original text fitting oldStart
is supplied as parameter.ReplaceVisitor.visit()public static int fUr(CharSequence quell, StringBuilder dest, CleverSSS oldStart, CleverSSS oldEnd, TextHelper.ReplaceVisitor repl)
source will be appended to the
StringBuilder dest. Hereby any sequence in source
consisting ofoldStart, any sequence and oldEndCleverSSS.where(quell, index)).repl.visit() is called with those three
sequences as parameters. As oldStart and oldEnd the brackets found in
quell are supplied to the visitor. (They might differ in case and length
to the CleverSSS's internal search sequence.) The value returned
by the TextHelper.ReplaceVisitor's method
visit() will be put to dest instead
of that "block of three". If null is returned by the visitor
that spot will be transfered unchanged and this will not be counted
as replacement.source was transferred unmodified to the
StringBuilder dest.oldEnd is null only oldStart is searched for in
source and the TextHelper.ReplaceVisitor's method
visit() will be called so
visit(null, oldStart, null).oldEnd is not null, a (last) finding of oldStar
without closing oldEnd will not be regarded add treated as
hit.CleverSSS objects
as matchers any flexibility in optionally ignoring case or white space
as well as CleverSSS's inheritor's (like RK or
KMP) speed is featured here.ReplaceVisitor.visit()public static int fUr(CharSequence source, StringBuilder dest, CleverSSS oldStart, CleverSSS oldEnd, String newText, boolean ckWd)
source will be appended to the
StringBuilder dest. Hereby any sequence in source
consisting ofoldStart, any sequence and oldEndCleverSSS.where(source, index)).(oldStart anyText oldEnd) will be completely
replaced by the String newText. If newText is null or
empty the block found is effectively removed.StringBuilder dest has not been
touched.fUr(CharSequence, StringBuilder, CleverSSS, CleverSSS, ReplaceVisitor)
!oldEnd is null or empty only oldStart is searched for
in source and just the text block found by oldStart
will be replaced.oldEnd is not null, a (last) finding of oldStart
without closing oldEnd will not be regarded and treated as
hit.CleverSSS objects as matchers any flexibility like
optionally ignoring case or white space as well as CleverSSS'
inheritor's (like RK or KMP)
speed is available here.ckWd
or "check for (pure text)
word". When true the surrounding characters of a text (block)
to be replaced are looked at: [ or * the
block is accepted (as never part of a href=" or src=" or
in markdown always a text) for replacement.<= 32 (poor man's
isWhiteSpace) the block's replacement is rejected.] ! ; , ? * or
(poor man's) white space the block is accepted (as no one should
use those as part of a path).] ! ; , ? *
or (poor man's) white space the block is accepted. Otherwise it is
rejected. Considering the second character, also, allows for a
a dot as well as an additional character for plural (German)
genitive, dative or else.FuR's hyphenation of words in links.
Example (German):"Feuerwehr. " may be hyphenated as Feuer­wehr.
but "./Feuerwehr.pdf" would never. source - the text to be appended to dest with replacementsdest - where to append source (with replacements tooldStart - text (or its start) to be replacedoldEnd - optional (closing) end of text to be replacednewText - the replacement textckWd - check if text to be replaced is (probably) a pure text word)FuRpublic static int indexOf(CharSequence sequ, CharSequence sub, int sI, boolean ignoreCase)
String.indexOf(String, int)
except for optionally ignoring case. Additionally by accepting any
CharSequences instead of Strings only this method is more
versatile.sub is searched for more than once using
the same settings on ignoring case or white space it is better to
make a CleverSSS
object for it and use that's search methods.sequ - the String to be searched withinsub - the Substring to be found in sequsI - the index in sequ to start the search for sub
(<0 is regarded as 0)ignoreCase - true means ignore case in the matching processpublic static int indexOfOpt(CharSequence sequ, CharSequence sub, int sI, boolean ignoreCase)
indexOf(CharSequence, CharSequence, int, boolean).sub (also ignoring case if so opted) is not
repeated within sub.indexOf() or
one of CleverSSS (see hint below) inheritors instead.sub's first
character being unique in sub (optionally ignoring case).sub "PD323S", "aBB" or
"$Date: " are OK, but "PD3PD323S" or
"aaBB" are not. The reason is that this method would not hit
"...aaaBB..." by "aaBB" e.g. CleverSSS's and its inheritors methods
where(),
indexOf(),
lastWhere.. etc.
switch to a similar optimistic search automatically.sequ - the String to be searched within.sub - the Substring to be found in sequ.sI - the index in sequ to start the search for sub
(<0 is regarded as 0)ignoreCase - true means ignore case in the matching processsequ or -1public static int lastIndexOf(CharSequence sequ, CharSequence sub)
String.lastIndexOf(String) but with case insensitive match and
more freedom for the types CharSequence instead of String
only.lastIndexOf(sequ, sub, -1, true).sequ - the sequence, which is searched in.sub - the (sub) sequence searched for.indexOf()public static int lastIndexOf(CharSequence sequ, CharSequence sub, int sI)
String.lastIndexOf(String,int) but with case insensitive match.sequ - the sequence, which sub is searched in.sub - the (sub) sequence searched for.sI - the character in sequ, the search is started
(default from the end).indexOf()public static int lastIndexOf(CharSequence sequ, CharSequence sub, int sI, boolean ignoreCase)
String.lastIndexOf(String,int) with the additional ability to
(optionally) ignore case.sequ - the sequence, which white space is searched insub - the (sub) sequence searched for.sI - the character in sequ, the search is started
(default from the end).ignoreCase - true: ignore case for fittingindexOf()public static int lastIndexOfWS(CharSequence sequ, int sI)
sequ.String.trim() — which
means breaking white space.sequ - the sequence, which white space is searched in.indexOf()public static int equalsTil(CharSequence sequ, int sI, CharSequence seq2, boolean ignoreCase)
String.equals(Object)
respectively .equalsIgnoreCase(String)) two character sequences
character by character.sequ - The first character sequence (pattern from sI).sI - The spot in sequ, where the matching will start
(<0 is taken as 0)seq2 - The second character sequence; matching object, starting index
here is always 0.ignoreCase - if true matching is not case sensitivepublic static int equalsTil(CharSequence[] sequences, boolean ignoreCase)
equalsTil(CharSequence, int, CharSequence, boolean) (with
sI = 0 and ignoreCase forwarded) to any pair of sequences.
The maximum of all returned values is returned.sequences. Applied to
English or German days of week the return value will be 1. This means,
that two characters ("Mo") will unambiguously abbreviate days
of week in these languages. For Portuguese days of week 2 would be
returned, as you need three letter abbreviations to distinguish
Seg./Sex.sequences - The sequences to be pairwise matchedignoreCase - if true matching is not case sensitivepublic static char zif(int value)
value - the value for the least significant hexadecimal digitpublic static char dig(int value)
value - the value in the range 0..100 for the least significant
decimal digitpublic static String twoDigitHex(int value)
value's lower 8 bits
is returned as String.twoDigitHex(Appendable, int) instead of this method.
value - the numberpublic static Appendable twoDigitHex(Appendable dest, int value)
dest (generated StringBuilder if supplied as null)
is the two digit hexadecimal representation of value's lower 8
bits.dest - destination to append to; if null dest is made as
StringBuilder with initial capacity of 10value - the numbertwoDigitDec(Appendable, int),
fourDigitHex(Appendable, int),
sixDigitHex(Appendable, int),
eightDigitHex(Appendable, int)public static Appendable fourDigitHex(Appendable dest, int value)
dest (generated StringBuilder if supplied as null)
is the four digit hexadecimal representation of value's lower 16
bits.dest - destination to append to; if null dest is made as
StringBuilder with initial capacity of 10twoDigitHex(Appendable, int),
sixDigitHex(Appendable, int),
eightDigitHex(Appendable, int)public static Appendable sixDigitHex(Appendable dest, int value)
dest (generated StringBuilder if supplied as null)
is the six digit hexadecimal representation of value's lower 24
bits. This representation is quite usual for 24 bit RGB colours.dest - destination to append to; if null dest is made as
StringBuilder with initial capacity of 12Color,
twoDigitDec(Appendable, int),
twoDigitHex(Appendable, int),
fourDigitHex(Appendable, int),
eightDigitHex(Appendable, int)public static Appendable eightDigitHex(Appendable dest, int value)
dest (generated StringBuilder if supplied as null)
is the six digit hexadecimal representation of value's lower 24
bits. This representation is quite usual for 24 bit RGB colours.dest - destination to append to; if null dest is made as
StringBuilder with initial capacity of 14Color,
twoDigitDec(Appendable, int),
twoDigitHex(Appendable, int),
fourDigitHex(Appendable, int),
sixDigitHex(Appendable, int)public static Appendable append(Appendable dest, byte[] bA)
dest (generated StringBuilder if supplied as null)
will be the content of the array bA as a sequence of two digit
hex numbers (like made by
zweiStellHex()). The numbers
are separated by ", " (comma blank).dest - destination to append to; if null dest is made as
StringBuilder with initial capacity reserve of 20public static Appendable append(Appendable dest, byte[] bA, int off, int len)
dest
will be the max. len bytes of the array bA starting from
index off as a sequence of two digit hex numbers (like made by
zweiStellHex()). The numbers
are separated by ", " (comma blank).dest - destination to append to; if null dest is made as
StringBuilder with initial capacity reserve of 20len - wished number of bytes processed, will be limited if too
large; < 0 means as much as possibleoff - staring index in bA; < 0 is taken as 0public static Appendable twoDigitDec(Appendable dest, int value)
dest (generated StringBuilder if supplied as null)
is the two digit decimal representation of value if in the range
0..99's. Otherwise two blanks are appended.dest - destination to append to; if null dest is made as
StringBuilder with initial capacity of 6value - the numberpublic static Appendable formDec(Appendable dest, int value, int width)
dest (generated StringBuilder if supplied as null)
is the decimal representation of value filled from left with
blanks to get at least width (1..38).dest - destination to append to; if null dest is made as
StringBuilder with initial capacity of width + 4value - the numberwidth - the minimal field width (max. 38) filled from left with
blanks if the number is shorter.public static String twoDigit(int value)
value and 0 return "00".value > 100 the modulo 100 will be taken.value - the numberpublic static String threeDigit(int value)
value and 0 return "000".value > 1000 the modulo 1000 will be taken.value - the numberpublic static boolean checkMac(StringBuilder leMac)
leMac - containing just one (correct) MAC address + nothingpublic static String checkLanguage(CharSequence language, CharSequence defValue)
ComVar.UL or "en" will be returned.language - the language (1st choice)defValue - the language (default)checkRegion(CharSequence, CharSequence),
trimUq(CharSequence, String)public static String checkRegion(CharSequence region, CharSequence defValue)
ComVar.UR or GB will be returned.region - the region (1st choice)defValue - the region (default)checkLanguage(CharSequence, CharSequence),
trimUq(CharSequence, String)public static String unComment(String s, char stC, char endC, boolean nested, CharSequence repl)
stC (opening brace ( e.g.) and ending with endC
(closing brace ) e.g.) will be removed from
the s and replaced by repl (if that is not empty).nested is true the parethis is nested. In that case within
" with a ( com(en)t ) !" would "( com(en)t )" be
recognised as comment and not "( com(en)".s's end will be regarded as the closing of the comment even if
the parethis might not have been closed. If and stC and
endC are equal nested is true everything starting
from the first occurrence of stC will be removed or replaced.s is returned as is.s - the String to "uncomment"public static int indexOf(String text, String[] list)
public static String[] prepParams(String[] args, String commSt, boolean unQuote)
args supplied. The returned array is either empty
or a newly created one; the latter may be a complete copy.args is null or empty (length 0) the empty array
ComVar.NO_STRINGS will be returned.args will be put into the (new) array
returned in their sequence. This copying ends where the (sub) sequence
commSt (begin of comment) is detected within one such String
that is not enclosed in quotes.args that are null will not be copied
to the new array.args and it's last String
may also be shorter (by the comment removed) than its counterpart in
the original args.args - the original parameter arraycommSt - the start sequence for comment (if not null or empty)unQuote - if true parameter enclosed in quotation marks (")
will get them removedpublic static String[] prepParams(CharSequence argLine, String commSt, boolean unQuote)
argLine
to an array of Strings.argLine will be cut to pieces separated by white space or
enclosed in double quotes ("). These pieces will be put into a
String array and returned as such.commSt (comment start) in one of the
pieces not in quotes will end that transfer to the target array.argLine - the "e;line" with the parameterscommSt - the start sequence for comment (if not null or empty)unQuote - if true parameter enclosed in quotation marks (")
will get them removedsplitCsWS(CharSequence)public static String[] prepParams(CharSequence argLine, int endArg)
argLine
to an array of Strings.argLine will be cut to pieces separated by white space or
enclosed in double quotes ("). These pieces will be put into a
String array and returned as such.endArg. If
endArg is low enough return[endArg] will contain
everything after the first whitespace separating the preceding
element.prepParams("a bc u h xx ", 2) endArg == 0 will return the argLine
without preceding white space in one String packed in a String arrays
of length 1.argLine - the "e;line" with the parametersendArg - the maximum index of the last Sting (element) returnedsplitCsWS(CharSequence),
splitWords(String),
prepParams(CharSequence, String, boolean)public static String[] splitWords(String origContent)
origContent
to an array of Strings.origContent will be cut to pieces separated by white space, comma
(,), semicolon (;), braces (()), quotes ("'), ETligature
(&) or colon (:). Single characters so separated will be ignored.
These pieces will be put into a String array and returned as such.origContent - the "e;line" with the parametersprepParams(CharSequence, String, boolean)public static String[] splitCsWS(CharSequence input)
input) at comma,
semicolon or white space, mostly like described for
getCommaSemicolonWSpattern(). Additionally this method
regards subsequences enclosed in quotes as one piece or token.StringTokenizer or a regular expression like
getCommaSemicolonWSpattern() with
getCommaSemicolonWSpattern().split(input, -1). Regular
expressions are even more costly than the
StringTokenizer, but would avoid the following
mistake:StringTokenizer
(using " ,;\t\n\r" as pattern) would see for
"a ; ; , , b" only one instead of four separations
giving only two instead of five token returned by a suitable regular
expression and by this method.input - the character sequence to tokeniseComVar.NO_STRINGSgetCommaSemicolonWSpattern(),
ComVar.NO_STRINGS,
splitWords(String)public static int countParams(String[] args)
parameters not evaluated and cleared by
partial parsing.args - the parameter arrayprepParams(String[])public static String prepParams(String[] args)
args - the parameterscountParams(String[])public static boolean shouldQuote(CharSequence akt)
public static String checkMail(CharSequence adr, CharSequence defaultServer, boolean forceServer)
adr fulfils (at lest) the minimal / basic
requirements on a robust (ASCCI) mail address. The server part, if
missing, will be added by the value of defaultServer resulting in
adr@defaultServer.forceServer true a server part may already be given
in the parameter adr but that must then be equal to
defaultServer.public static Appendable format(Appendable dest, CharSequence name, CharSequence[] sA, int sLen)
sA now named name will be output to
dest (made as StringBuilder if supplied as null).dest - destination to append to; if null dest is made as
StringBuilder with initial capacity of 50 + 16 * sA's lengthname - the name to be given to sA;
null will be taken as "..."sA - the String[] to be formatted / listedsLen - if >= 0 and < sA.length used to reduce the effective
length of sA to formatwrite(PrintWriter, CharSequence, CharSequence[])public static void write(PrintWriter out, CharSequence name, CharSequence[] sA)
sA now named name will be output to
out. The multi-line format is equivalent to the Java's
initialised String[] declaration syntax.format(out, name, sA, 0,
except for doing nothing when out is 0 and outputting always the whole
String array
public static StringBuilder formatDuration(StringBuilder dest, long dur)
dur is duration in ms (milliseconds). According to its magnitude
it will formatted in four ways, namely like 9788ms, 3599s, 1h00min
or 1d00h00mindest - destination to append to; if null dest is made as
StringBuilder with initial capacity of 16dur - the durationApp.getExecTimeMs()public static Pattern getCommaSemicolonWSpattern()
TextHelper.getCommaColonWSpattern().split("a,b, c , d , e
,, f g ,, ", -1)trimUq(CharSequence, String)).
TextHelper.getCommaColonWSpattern().split(string, -1)
TextHelper.splitCcWS(string)split() is
preferable over
String.split().public static StringBuilder messageFormat(StringBuilder dest, CharSequence pattern, Object args)
MessageFormat is much to
circumstantial or just overkill.ChoiceFormat, Currency etc. will not
be supported here, however the most flexible time / date formatting by
using pattern directly given in the format strings.Object[] containing
Integers is accepted as well. Additionally the case of just one
parameter (the frequent {0} only case) is supported by supplying just the
object instead of a new Object[]{arg} with just that one
element.toString() of the argument
indexed by the number. For theses simple cases pattern is compatible
between this method and the format()-methods of
MessageFormat.App inheritors the object
itself by grace of the method App.getMessageComponent(int); a
(inter) nationalised start message generated by this schema is returned by
the method
App.twoLineStartMsg().Boolean, anything between
the last index digit and the closing } ({21Dateien?Datei} e.g. or
{21chicken?mice}) is used as format String for the boolean value. If that
contains a ? this separates two parts the first taken for true and the
last for false. Without the ? the whole thing (except the index digits
is taken for true and nothing for false. The same applies if the argument
is a number (int or Integer), where value != 1 (= plural) is
taken as boolean; examples:dest - StringBuilder to append to; if null it is made with a
starting capacity of 81pattern - the pattern to append toargs - An array of the arguments; may be of type Object[] or
int[]; null or empty means pattern being appended to
dest uninterpreted.TextHelper.MessageComponents whose method
TextHelper.MessageComponents.getMessageComponent(int) will be
called to provide (dynamically) the arguments denoted in
pattern.AppLangMappublic static TextHelper.MessageComponents makeMessageComponents(Object[] oa)