Class StringUtil


  • public class StringUtil
    extends java.lang.Object
    Collection of string manipulation utilities
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtil()  
      StringUtil​(long cPtr, boolean cMemoryOwn)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void delete()  
      static long getCPtr​(StringUtil obj)  
      static java.lang.String getDirectoryName​(java.lang.String path)
      The directory part of a path name.

      The function simply returns everything up to and including the last slash
      or backslash.
      static java.lang.String getFileExtension​(java.lang.String filename)
      The extension of a file name.

      The extension is everything that follows the last '.'.

      The '.' is included in the extension returned, so that if that if the
      file has no extension, then the empty string can be returned.

      static java.lang.String getFileName​(java.lang.String pathAndFileName)
      Extract the file name (including extension) from a string containing full name
      including the directory.

      The function simply returns everything efter the last slash
      or backslash.
      static java.lang.String getRelativeDirectoryName​(java.lang.String path, java.lang.String dir_name)
      The directory part of a path name relative to a root directory.

      The function returns everything up to and including the last slash
      or backslash.
      static boolean isAbsoluteFileName​(java.lang.String file)
      True if the file name file is an absolute file name.
      static java.lang.String patternToRegEx​(java.lang.String pattern)
      Converts a string pattern with wild card characters * and ? into a regular
      expression

      The format of the regular expression matches std::regex.

      static java.lang.String quote​(java.lang.String str)
      The string str enclosed in single-quotes.

      Use this for quoting of strings in user error messages.
      static java.lang.String ranName​(java.lang.String prefix)
      creates a name based on a prefix and a random integer between
      0xFF and 0xFFFFFF
      static java.lang.String removeWhiteSpace​(java.lang.String str)
      Removes space, tab and new line from string
      static java.lang.String replaceBackslash​(java.lang.String file)
      Replace '\' with '/' everywhere in the file name file.
      static pair_b_d toDouble​(java.lang.String str)
      Return (true, val) if str parses as a double with value
      val and (false, 0) otherwise.
      static pairBoolVectorDouble toDoubles​(vector_s words)
      Return (true, vals) if words parses as a sequence of doubles with values
      vals and (false, []) otherwise.
      static pair_b_i toInt​(java.lang.String str)
      Return (true, val) if str parses as a int with value
      val and (false, 0) otherwise.
      static pairBoolVectorInt toInts​(vector_s words)
      Return (true, vals) if words parses as a sequence of ints
      with values vals and (false, []) otherwise.
      static pair_b_l toLong​(java.lang.String str)
      Return (true, val) if str parses as a int with value
      val and (false, 0) otherwise.
      static pairBoolVectorLong toLongs​(vector_s words)
      Return (true, vals) if words parses as a sequence of ints
      with values vals and (false, []) otherwise.
      static java.lang.String toLower​(java.lang.String str)
      The lowercase of a string.

      static pair_b_ui toUInt​(java.lang.String str)
      Return (true, val) if str parses as a int with value
      val and (false, 0) otherwise.
      static pairBoolVectorUInt toUInts​(vector_s words)
      Return (true, vals) if words parses as a sequence of ints
      with values vals and (false, []) otherwise.
      static pair_b_ul toULong​(java.lang.String str)
      Return (true, val) if str parses as a int with value
      val and (false, 0) otherwise.
      static pairBoolVectorULong toULongs​(vector_s words)
      Return (true, vals) if words parses as a sequence of ints
      with values vals and (false, []) otherwise.
      static java.lang.String toUpper​(java.lang.String str)
      The uppercase of a string.

      static vector_s words​(java.lang.String str)
      Split str into words at space borders.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringUtil

        public StringUtil​(long cPtr,
                          boolean cMemoryOwn)
      • StringUtil

        public StringUtil()
    • Method Detail

      • getCPtr

        public static long getCPtr​(StringUtil obj)
      • delete

        public void delete()
      • isAbsoluteFileName

        public static boolean isAbsoluteFileName​(java.lang.String file)
        True if the file name file is an absolute file name.
      • replaceBackslash

        public static java.lang.String replaceBackslash​(java.lang.String file)
        Replace '\' with '/' everywhere in the file name file.
      • removeWhiteSpace

        public static java.lang.String removeWhiteSpace​(java.lang.String str)
        Removes space, tab and new line from string
      • getDirectoryName

        public static java.lang.String getDirectoryName​(java.lang.String path)
        The directory part of a path name.

        The function simply returns everything up to and including the last slash
        or backslash. If there is no such slash or backslash, the empty string is
        returned.

        Parameters:
        path - [in] The path name.

        Returns:
        The directory name for the path.
      • getRelativeDirectoryName

        public static java.lang.String getRelativeDirectoryName​(java.lang.String path,
                                                                java.lang.String dir_name)
        The directory part of a path name relative to a root directory.

        The function returns everything up to and including the last slash
        or backslash. If there is no such slash or backslash, the empty string is
        returned.

        Parameters:
        path - [in] The path name.

        dir_name - [in] The root directory name.

        Returns:
        The relative directory name for the path.
      • getFileName

        public static java.lang.String getFileName​(java.lang.String pathAndFileName)
        Extract the file name (including extension) from a string containing full name
        including the directory.

        The function simply returns everything efter the last slash
        or backslash. If there is no such slash or backslash, the original string is returned

        Parameters:
        pathAndFileName - [in] The path and filename .

        Returns:
        The file name.
      • getFileExtension

        public static java.lang.String getFileExtension​(java.lang.String filename)
        The extension of a file name.

        The extension is everything that follows the last '.'.

        The '.' is included in the extension returned, so that if that if the
        file has no extension, then the empty string can be returned.

        Parameters:
        filename - [in] The file name.

        Returns:
        The file name extension.
      • toUpper

        public static java.lang.String toUpper​(java.lang.String str)
        The uppercase of a string.

        Parameters:
        str - [in] A string to uppercase.

        Returns:
        str converted to upper case.
      • toLower

        public static java.lang.String toLower​(java.lang.String str)
        The lowercase of a string.

        Parameters:
        str - [in] A string to lowercase.

        Returns:
        str converted to lower case.
      • quote

        public static java.lang.String quote​(java.lang.String str)
        The string str enclosed in single-quotes.

        Use this for quoting of strings in user error messages.
      • words

        public static vector_s words​(java.lang.String str)
        Split str into words at space borders.
      • toDouble

        public static pair_b_d toDouble​(java.lang.String str)
        Return (true, val) if str parses as a double with value
        val and (false, 0) otherwise.
      • toInt

        public static pair_b_i toInt​(java.lang.String str)
        Return (true, val) if str parses as a int with value
        val and (false, 0) otherwise.
      • toUInt

        public static pair_b_ui toUInt​(java.lang.String str)
        Return (true, val) if str parses as a int with value
        val and (false, 0) otherwise.
      • toLong

        public static pair_b_l toLong​(java.lang.String str)
        Return (true, val) if str parses as a int with value
        val and (false, 0) otherwise.
      • toULong

        public static pair_b_ul toULong​(java.lang.String str)
        Return (true, val) if str parses as a int with value
        val and (false, 0) otherwise.
      • toDoubles

        public static pairBoolVectorDouble toDoubles​(vector_s words)
        Return (true, vals) if words parses as a sequence of doubles with values
        vals and (false, []) otherwise.
      • toInts

        public static pairBoolVectorInt toInts​(vector_s words)
        Return (true, vals) if words parses as a sequence of ints
        with values vals and (false, []) otherwise.
      • toUInts

        public static pairBoolVectorUInt toUInts​(vector_s words)
        Return (true, vals) if words parses as a sequence of ints
        with values vals and (false, []) otherwise.
      • toLongs

        public static pairBoolVectorLong toLongs​(vector_s words)
        Return (true, vals) if words parses as a sequence of ints
        with values vals and (false, []) otherwise.
      • toULongs

        public static pairBoolVectorULong toULongs​(vector_s words)
        Return (true, vals) if words parses as a sequence of ints
        with values vals and (false, []) otherwise.
      • patternToRegEx

        public static java.lang.String patternToRegEx​(java.lang.String pattern)
        Converts a string pattern with wild card characters * and ? into a regular
        expression

        The format of the regular expression matches std::regex.

        Parameters:
        pattern - [in] pattern with wild card characters
        Returns:
        patterns expressed as regular expression.
      • ranName

        public static java.lang.String ranName​(java.lang.String prefix)
        creates a name based on a prefix and a random integer between
        0xFF and 0xFFFFFF
        Parameters:
        prefix -
        Returns: