Class StringUtil


  • public final class StringUtil
    extends Object
    Class for holding static utility functions for string handling: quoting and for parsing numbers.
    Author:
    Kim Hansen
    • Constructor Detail

      • StringUtil

        private StringUtil()
    • Method Detail

      • appendChar

        private static void appendChar​(StringBuffer buf,
                                       char c)
      • jQuote

        public static String jQuote​(String str)
        Quotes string as Java Language string literal. Returns the string "null" (with length 4) if str is null. Code taken from http://freemarker.sourceforge.net/
        Parameters:
        str -
        Returns:
        the string encoded and quoted
      • jQuote

        public static String jQuote​(char[] cbuf,
                                    int len)
        Quotes the first len characters of cbuf as Java Language string literal. Returns string null if s is null.
        Parameters:
        cbuf - the buffer
        len - How much of the buffer to quote
        Returns:
        the string encoded and quoted: Starts and ends with "
      • parseBoolean

        public static boolean parseBoolean​(String line)
      • toString

        public static String toString​(boolean bool)
        Returns the string representation of booleans in octave: 1 for true and 0 for false.
      • toString

        public static <T> String toString​(T obj)
        Returns the string representation of the object obj which is defined also for null returning just "null".
      • parseDouble

        public static double parseDouble​(String string)
        This is almost the same as Double.parseDouble(), but it handles a few more versions of infinity.
        Parameters:
        string -
        Returns:
        The parsed Double