Package org.eclipse.rdf4j.common.text
Class StringUtil
- java.lang.Object
-
- org.eclipse.rdf4j.common.text.StringUtil
-
public class StringUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
appendN(char c, int n, StringBuilder sb)
Appends the specified character n times to the supplied StringBuilder.static String
concat(String... strings)
Deprecated.static String[]
decodeArray(String encodedArray)
Deprecated.static String
deriveInitialText(String text)
Deprecated.static String
encodeArray(String[] array)
Deprecated.static String
getAllAfter(String string, char separatorChar)
Deprecated.static String
getAllBefore(String string, char separatorChar)
Deprecated.static String
gsub(String olds, String news, String text)
Substitute String "old" by String "new" in String "text" everywhere.static boolean
isGarbageText(String text)
Deprecated.static void
simpleEscapeIRI(String str, Appendable appendable, boolean escapeUnicode)
Escapes a string to a (mostly) conforming IRI value and append it to the appendable.static String
trimDoubleQuotes(String text)
Removes the double quote from the start and end of the supplied string if it starts and ends with this character.
-
-
-
Method Detail
-
gsub
public static String gsub(String olds, String news, String text)
Substitute 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.- Parameters:
olds
- The String to be substituted.news
- The String is the new content.text
- The String in which the substitution is done.- Returns:
- The result String containing the substitutions; if no substitutions were made, the result is 'text'.
-
simpleEscapeIRI
public static void simpleEscapeIRI(String str, Appendable appendable, boolean escapeUnicode) throws IOException
Escapes 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 thanParsedIRI.create(String)
for valid IRI (without percents) and much faster for IRI with invalid (percent-encoded) characters, though it is less accurate.- Parameters:
str
-appendable
-escapeUnicode
- escape non-ASCII values numerically- Throws:
IOException
-
getAllAfter
@Deprecated public static String getAllAfter(String string, char separatorChar)
Deprecated.Returns all text occurring after the specified separator character, or the entire string when the separator char does not occur.- Parameters:
string
- The string of which the substring needs to be determined.separatorChar
- The character to look for.- Returns:
- All text occurring after the separator character, or the entire string when the character does not occur.
-
getAllBefore
@Deprecated public static String getAllBefore(String string, char separatorChar)
Deprecated.Returns all text occurring before the specified separator character, or the entire string when the separator char does not occur.- Parameters:
string
- The string of which the substring needs to be determined.separatorChar
- The character to look for.- Returns:
- All text occurring before the separator character, or the entire string when the character does not occur.
-
encodeArray
@Deprecated public static String encodeArray(String[] array)
Deprecated.Encodes an array of Strings into a single String than can be decoded to the original array using the corresponding decode method.Useful for e.g.storing an array of Strings as a single entry in a Preferences node.- Parameters:
array
- array of strings- Returns:
- single string
-
decodeArray
@Deprecated public static String[] decodeArray(String encodedArray)
Deprecated.Decodes a String generated by encodeArray.- Parameters:
encodedArray
-- Returns:
- array of strings
-
deriveInitialText
@Deprecated public static String deriveInitialText(String text)
Deprecated.Derives the initial text from the supplied text.The returned text excludes whitespace and other special characters and is useful for display purposes (e.g.previews).- Parameters:
text
-- Returns:
-
isGarbageText
@Deprecated public static boolean isGarbageText(String text)
Deprecated.Titles shorter than MIN_TITLE_LENGTH and long titles that don't contain a single space character are considered to be garbage.- Parameters:
text
-- Returns:
- true if considered garbage
-
appendN
public static void appendN(char c, int n, StringBuilder sb)
Appends the specified character n times to the supplied StringBuilder.- Parameters:
c
- The character to append.n
- The number of times the character should be appended.sb
- The StringBuilder to append the character(s) to.
-
trimDoubleQuotes
public static String trimDoubleQuotes(String text)
Removes 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.- Parameters:
text
- The string to remove the double quotes from.- Returns:
- The trimmed string, or a reference to text if it did not start and end with double quotes.
-
concat
@Deprecated public static String concat(String... strings)
Deprecated.Concatenate a number of Strings. This implementation uses a StringBuilder.- Parameters:
strings
- the String to concatenate- Returns:
- a String that is the results of concatenating the input strings.
-
-