Class StringUtil


  • public class StringUtil
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static char[] IRI_DONT_ESCAPE  
    • 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, java.lang.StringBuilder sb)
      Appends the specified character n times to the supplied StringBuilder.
      static java.lang.String gsub​(java.lang.String olds, java.lang.String news, java.lang.String text)
      Deprecated.
      use instead.
      private static java.lang.String hex​(int c)  
      static void simpleEscapeIRI​(java.lang.String str, java.lang.Appendable appendable, boolean escapeUnicode)
      Escapes a string to a (mostly) conforming IRI value and append it to the appendable.
      static java.lang.String trimDoubleQuotes​(java.lang.String text)
      Removes the double quote from the start and end of the supplied string if it starts and ends with this character.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • IRI_DONT_ESCAPE

        private static final char[] IRI_DONT_ESCAPE
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • gsub

        @Deprecated(since="4.0.0")
        public static java.lang.String gsub​(java.lang.String olds,
                                            java.lang.String news,
                                            java.lang.String text)
        Deprecated.
        use instead.
        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'.
      • hex

        private static java.lang.String hex​(int c)
      • simpleEscapeIRI

        public static void simpleEscapeIRI​(java.lang.String str,
                                           java.lang.Appendable appendable,
                                           boolean escapeUnicode)
                                    throws java.io.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 than ParsedIRI.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:
        java.io.IOException
      • appendN

        public static void appendN​(char c,
                                   int n,
                                   java.lang.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 java.lang.String trimDoubleQuotes​(java.lang.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.