public class StringUtil extends Object
Method SummaryModifier and TypeMethodDescription
static voidAppends the specified character n times to the supplied StringBuilder.
static voidEscapes a string to a (mostly) conforming IRI value and append it to the appendable.
static StringRemoves the double quote from the start and end of the supplied string if it starts and ends with this character.
gsubSubstitute String "old" by String "new" in String "text" everywhere. This is a static util function that I could not place anywhere more appropriate. The name of this function is from the good-old awk time.
olds- The String to be substituted.
news- The String is the new content.
text- The String in which the substitution is done.
- The result String containing the substitutions; if no substitutions were made, the result is 'text'.
simpleEscapeIRIpublic static void simpleEscapeIRI
(String str, Appendable appendable, boolean escapeUnicode) throws IOExceptionEscapes a string to a (mostly) conforming IRI value and append it to the appendable. Non-ASCII (valid) values can optionally be numerically encoded by setting escapeUnicode to true. Most characters that are invalid in an IRI - like a white space or control character - are percent-encoded. This is slightly faster than
ParsedIRI.create(String)for valid IRI (without percents) and much faster for IRI with invalid (percent-encoded) characters, though it is less accurate.
escapeUnicode- escape non-ASCII values numerically
appendNpublic static void appendN
(char c, int n, StringBuilder sb)Appends the specified character n times to the supplied StringBuilder.
c- The character to append.
n- The number of times the character should be appended.
sb- The StringBuilder to append the character(s) to.
trimDoubleQuotesRemoves the double quote from the start and end of the supplied string if it starts and ends with this character. This method does not create a new string if text doesn't start and end with double quotes, the text object itself is returned in that case.
text- The string to remove the double quotes from.
- The trimmed string, or a reference to text if it did not start and end with double quotes.