Class StringUtil

java.lang.Object
org.cip4.jdflib.util.StringUtil

public class StringUtil extends Object
collection of static string utilities
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    class that provides additional functionality for replacing string
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Deprecated.
    use UrlUtil.m_URIEscape
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    addToken(String strWork, String delim, String newToken)
    replace a token in a string
    static int
    compare(String c0, String c1, boolean ignoreCase)
    static implementation of compare for any comparable object that gracefully handles null
    null is always the smallest
    static int
    compareTo(double d1, double d2)
    return -1 if d1 < d2 , 0 if d1==d2 ; +1 if d1>d2 are within a range of epsilon or close enough to be serialized identically
    static String
    concat(String s1, String s2, String delim)
     
    static void
    concatStrings(VString vS, String appendString)
    add the string appendString to all Strings in VString vs
    static String
    create a string from an input stream
    static boolean
    return true if a equals b or both are null or ""
    static boolean
    equals(String attribute, String attribute2, double delta)
    simple comparison of strings with some heuristics
    static byte[]
    escape(byte[] a_toEscape, String strCharSet, String strEscapeChar, int iRadix, int iEscapeLen, int iEscapeBelow, int iEscapeAbove)
    escape a string by prepending escapeChar and a numerical representation of the string.
    static String
    escape(String strToEscape, String strCharSet, String strEscapeChar, int iRadix, int iEscapeLen, int iEscapeBelow, int iEscapeAbove)
    escape a string by prepending escapeChar and a numerical representation of the string.
    static String
    extension(String pathName)
    Deprecated.
    use URLUtil.extension
    static String
    fileToUrl(File f, boolean b)
    Deprecated.
    use UrlUtil.fileToUrl(f, b);
    static int
    find_last_not_of(String strWork, String strNotList)
    find the last character in strwork that is not in strNotList
    static String
    formatDouble(double d)
    returns a formatted double.
    static String
    formatDouble(double value, int precision)
    returns a formatted double.
    static String
    returns a formatted integer, replaces string constants with according int constants
    static String
    formatLong(long i)
    returns a formatted integer, replaces string constants with according int constants
    static Charset
     
    static org.cip4.jdflib.util.StringUtil.EDataType
     
    static String
    return null if s==null or s==def, else s
    used e.g.
    static int
    getDistance(String s1, String s2, boolean normalize, boolean ignoreCase, boolean ignoreEmpty)
    return the Levenschtein ditance where null is treated as ""
    static int
    getDistance(String s1, String s2, boolean normalize, boolean ignoreCase, boolean ignoreEmpty, boolean reduceSubstring)
     
    Deprecated.
    use @se EnumUtil.getEnumsVector
    static byte[]
    getHexBinaryBytes(byte[] unicodeArray)
    Decode a HexBinary encoded byte array back to Unicode
    static VString
    Deprecated.
    use @see EnumUtil.getNamesVector
    static String
    return null if s==null or s=="", else s
    used e.g.
    static String
    returns a random string for testing fun stuff - similar to unix fortune but biased towards monty python or the hitchhikers guide to the galaxy
    static byte[]
    getRawBytes(String strUnicode)
    get the raw bytes specified in strUnicode, bypassing all transcoders
    any character values above 255 is truncated (c=c&0xff)
    static String
    Deprecated.
    use URLUtil.getRelativePath(f, fCWD);
    static String
    getRelativeURL(File f, File baseDir)
    Deprecated.
    use getRelativeURL(File f, File fCWD, boolean bEscape128)
    static String
    getRelativeURL(File f, File baseDir, boolean bEscape128)
    Deprecated.
    use URLUtil.getRelativeURL
    static byte[]
    getUTF8Bytes(String strUnicode)
    return the UTF8 String strUnicode as Unicode byte array
    static String
    getUTF8String(byte[] utf8)
    get the unicode string representing the UTF8 representation of the byte buffer fall back on default encoding in case someone accidentally sends in non utf-8
    static boolean
    return false if s==null or s has only whotespace
    static boolean
    hasToken(String[] strWork, String token, int iSkip)
    check whether a vector of Strings contains a given token
    static boolean
    hasToken(String strWork, String token, String delim)
    Deprecated.
    use the 4 parameter version
    static boolean
    hasToken(String strWork, String token, String delim, int iSkip)
    check whether a String contains a given token
    static int
    index(String in, String search, int i)
     
    static int
    indexOfToken(String strWork, String token, String delim, int start)
    index of a token in a string
    static String
    intern(String value)
     
    static boolean
    isBoolean(String strWork)
    checks whether a string matches the boolean values "true" or "false"
    static boolean
    isDate(String strWork)
    checks whether a string matches the boolean values "true" or "false"
    static boolean
    return true if s==null or s==""
    static boolean
    are we null or empty or contain only an empty JDFAttributeMap
    static boolean
    isEqual(double d1, double d2)
    return true if d1 and d2 are within a range of epsilon or close enough to be serialized identically
    static boolean
    isEqual(double d1, double d2, double delta)
    return true if d1 and d2 are within a range of epsilon or close enough to be serialized identically
    static boolean
    isID(String strWork)
    checks whether a string is an ID
    static boolean
    checks whether str reprents an integer
    static boolean
    checks whether str reprents an integer
    static boolean
    isNMTOKEN(String strWork)
    checks whether a string is a NMTOKEN
    static boolean
    isNMTOKENS(String strWork)
    checks whether a string is matches an NMTOKENS list
    static boolean
    isNMTOKENS(String strWork, boolean bID)
    checks whether a string is a NMTOKENS list
    static boolean
    checks whether a string is a number
    static boolean
    checks whether a string matches the boolean values "true" or "false"
    static boolean
    isUNC(String pathName)
    Deprecated.
    use URLUtil.isUNC(pathName)
    static boolean
    Deprecated.
    use UrlUtil.isWindowsLocalPath(pathName);
    static String
    leftStr(String strWork, int n)
    n > 0 substring(0, n) take the first n chars (leftmost) n < 0 substring(0, s.length()+n) take the string and cut n chars on the right example: string = "abcdefgh" string.leftStr( 2) = "ab" string.leftStr(-3) = "abcde"
    static int
     
    static boolean
    matches(String str, String regExp)
    match a regular expression using String.matches(), but also catch exceptions
    does NOT handle simplified regexp.
    static boolean
    match a regular expression using ignoring cases using String.matches(), but also catch exceptions and handle simplified regexp.
    static boolean
    matchesIgnoreCase(String str, String regExp, boolean alwaysSimple)
    match a regular expression using ignoring cases using String.matches(), but also catch exceptions and handle simplified regexp.
    static boolean
    matchesSimple(String str, String regExp)
    match a regular expression using String.matches(), but also catch exceptions and handle simplified regexp.
    static boolean
    matchesSimple(String str, String regExp, boolean alwaysSimple)
    match a regular expression using String.matches(), but also catch exceptions and handle simplified regexp.
    static String
    mime(String strWork)
    Deprecated.
    use MimeUtil.getMimeTypeFromExt(strWork);
    static String
    newExtension(String strWork, String newExt)
    Deprecated.
    use UrlUtil.newExtension
    static String
    normalize(String strWork)
    normalize a string by stripping and converting any internal whitespace to a single blank
    static String
    normalize(String strWork, boolean toLower)
    normalize a string by stripping and converting any internal whitespace to a single blank
    static String
    normalize(String strWork, boolean toLower, String replace)
    normalize a string by stripping and converting any internal whitespace to the value of replace
    static String
     
    static int
    numSubstrings(String strWork, String subString)
    counts the number of occurrences of subString in String the total number of occurrences is counted, e.g "aaa" contains "aa" twice
    static boolean
    parseBoolean(String s, boolean def)
    parses a string to boolean and catches any format exception "1" and "0" are treated as true and false respectively
    static double
    parseDouble(String s, double def)
    parses a string to double and catches any format exception
    static int
    parseInt(String s, int def)
    parses a string to integer and catches any format exception
    static long
    parseLong(String s, long def)
    parses a string to long and catches any format exception
    static String
    pathToName(String pathName)
    gets the file name from a path - regardless of the OS syntax that the path is declared in
    static int
    posOfToken(String strWork, String name, String separator, int iSkip)
    returns the position of the token, if it is in the String.
    The separator is excluded from the tokens.
    static String
    prefix(String strWork)
    Deprecated.
    use UrlUtil.prefix(strWork);
    static String
    removeToken(String strWork, int index, String delim)
    replace a token in a string
    static String
    removeToken(String strWork, String oldToken, String delim)
     
    static String
    replaceChar(String strWork, char c, String replaceString, int offset)
    replace multiple occurrences of a character in a given String
    static String
    replaceCharSet(String strWork, String charSet, String replaceString, int offset)
    replace any of a set of characters in a given String
    static String
    replaceString(String strWork, String toReplace, String replaceBy)
    replace a string in a given String if the replacement string is contained by the string to replace, recursively replace until no ocurrences of the original remain thus replaceString("a000000", "00", "0") will return "a0" rather than "a000"
    static String
    replaceToken(String strWork, int index, String delim, String newToken)
    replace a token in a string
    static String
    replaceToken(String strWork, String oldToken, String delim, String newToken)
     
    static String
    rightStr(String strWork, int n)
    get the end of a string n > 0 str.substring(str.length() - n) take the rightmost n chars n < 0 substring(-n) take the string and cut n chars on the left example: string = "abcdefgh" string.rightStr( 2) = "gh" string.rightStr(-3) = "defgh"
    static String
    setHexBinaryBytes(byte[] buffer, int len)
    get buffer as HexBinary
    any character values above 255 is truncated
    static String
    setRawBytes(byte[] buffer, int len)
    set a string to the raw bytes specified in buffer, bypassing all transcoders
    static byte[]
    setUTF8String(String strUnicode)
    Deprecated.
    use getUTF8Bytes instead
    static String
    setvString(String[] a, String sep, String front, String back)
    create a string from an array of tokens
    static String
    create a string from a vector of tokens
    static String
    setvString(List<?> v, String sep, String front, String back)
    create a string from a vector of tokens
    static String
    converts a simple regexp to a real regexp
    * --> (.*) (any # of chars)
    .
    static String
    simpleRegExptoRegExp(String simpleRegExp, boolean alwaysSimple)
    converts a simple regexp to a real regexp
    * --> (.*) (any # of chars)
    .
    static String
    sprintf(String format, Object[] objects)
    format a string using C++ sprintf functionality
    static String
    sprintf(String format, String template)
    format a string using C++ sprintf functionality
    static String
    sprintf(String format, List<String> vTemplate)
     
    static String
    stripNot(String work, String keepChars)
    returns a new string that has all characters stripped from work that are not in keepChars
    static String
    stripPrefix(String str, String prefix, boolean bIgnoreCase)
    strip a prefix, if it is there else return the string
    static String
    stripQuote(String str, String quote, boolean bTrim)
    strip leading and trailing quotes from a string
    static String
    substring(String strWork, int first, int last)
    similar to substring but also null safe and allowing negative numbers to count backwards
    static String
    token(String strWork, int index, String delim)
    get a single token from a String
    static VString
    tokenize(String strWork, String delim, boolean delim2token)
    return a vector of individual tokens
    Multiple consecutive delimitors are treated as one (similar to whitespace handling).
    static List<String>
    tokenize(List<String> l, String strIn, String strSep)
    constructs a VString by tokenizing a string
    static VString
    tokenizeBrackets(String strWork, char delimIn, char delimOut)
    tokenize while counting the referenced in and out so that internal tokens are skipped used e.g for "?:" of "()"
    static String
    trim(String work, String trimChars)
    returns a new string that has all characters trimmed from the front and back of work that are not in trimChars
    static String
    uncToUrl(String unc, boolean bEscape128)
    Convert a UNC path to a valid file URL or IRL note that some internal functions use network protocol and therefor performance may be non-optimal
    static String
    underToCamel(String toConvert)
     
    static byte[]
    unEscape(byte[] byteUnEscape, String strEscapeChar, int iRadix, int escapeLen)
    unescape a String which was escaped with the Java StringUtil.escape method
    static String
    unEscape(String strToUnescape, String strEscapeChar, int iRadix, int escapeLen)
    unescape a String which was escaped with the Java StringUtil.escape method
    static String
    Deprecated.
    use vs.getString(" ",null,null)
    static String
    wipeInvalidXML10Chars(String strText, String replace)
    replaces all chars that are not compatible with xml1.0
    static String
    write to a file
    static String
     
    static String
    Deprecated.
    060314 use KElement.xmlnsprefix
    static String
    zappTokenWS(String str, String delim)
    Returns a string with deleted whitespaces near 'delim' and from the both ends of the string (if they were there)
    tokenizes a given string 'str' into tokens without separators.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • getRandomString

      public static String getRandomString()
      returns a random string for testing fun stuff - similar to unix fortune but biased towards monty python or the hitchhikers guide to the galaxy
      Returns:
      a random string
    • zappTokenWS

      public static String zappTokenWS(String str, String delim)
      Returns a string with deleted whitespaces near 'delim' and from the both ends of the string (if they were there)
      tokenizes a given string 'str' into tokens without separators. Trims every token from both sides to remove the whitespaces and builds a new string from these tokens separated by 'delim'.
      Parameters:
      str - working string
      delim - the delimiter
      Returns:
      String - the modified string
    • write2String

      public static String write2String(IStreamWriter w)
      write to a file
      Parameters:
      file - the file to write
      w - the writer to write to
      Returns:
      the file that was created, null if snafu
    • sprintf

      public static String sprintf(String format, String template)
      format a string using C++ sprintf functionality
      Parameters:
      format - the format to print, see C++ spec for details
      template - - comma separated string - the values are parsed and the appropriate objects are created more objects exist in template than the number of '%' tokens in format, the remainder of objects is ignored duplicate '\\,' is taken as literal ','
      Returns:
      String the formatted string
      Throws:
      IllegalArgumentException - in case format and o do not match, i.e. not enough objects are passed to fill format
    • sprintf

      public static String sprintf(String format, List<String> vTemplate)
    • sprintf

      public static String sprintf(String format, Object[] objects)
      format a string using C++ sprintf functionality
      Parameters:
      format - the format to print, see C++ spec for details
      objects - the array of objects, either String, Double, Integer or ValuedEnum, if objects is longer than the number of '%' tokens in format, the remainder of objects is ignored The method works fairly loosely typed, thus doubles are printed as integers, Strings are converted to numbers, if possible etc.
      Returns:
      String the formatted string
      Throws:
      IllegalArgumentException - in case format and o do not match, i.e. not eough objects are passed to fill format
    • setvString

      public static String setvString(String[] a, String sep, String front, String back)
      create a string from an array of tokens
      Parameters:
      a - the token array
      sep - the separator between the tokens
      front - the front end of the string
      back - the back end of the string
      Returns:
      String - the vector as String default: setvString(v, JDFConstants.BLANK, null, null)
    • setvString

      public static String setvString(List<?> v)
      create a string from a vector of tokens

      default: setvString(v, JDFConstants.BLANK, null, null)

      Parameters:
      v - the token vector
      Returns:
      String - the vector as String
    • setvString

      public static String setvString(List<?> v, String sep, String front, String back)
      create a string from a vector of tokens
      Parameters:
      v - the token vector
      sep - the separator between the tokens
      front - the front end of the string
      back - the back end of the string
      Returns:
      String - the vector as String default: setvString(v, JDFConstants.BLANK, null, null)
    • leftStr

      public static String leftStr(String strWork, int n)
      n > 0 substring(0, n) take the first n chars (leftmost) n < 0 substring(0, s.length()+n) take the string and cut n chars on the right example: string = "abcdefgh" string.leftStr( 2) = "ab" string.leftStr(-3) = "abcde"
      Parameters:
      strWork - the string to work on
      n - number of characters to cut (negative) or retain (positive)
      Returns:
      the modified string
    • substring

      public static String substring(String strWork, int first, int last)
      similar to substring but also null safe and allowing negative numbers to count backwards
      Parameters:
      strWork - the string to work on
      first - the position of the starting character 0=first
      last - the position of the end character 0=last
      Returns:
      the modified string
    • rightStr

      public static String rightStr(String strWork, int n)
      get the end of a string n > 0 str.substring(str.length() - n) take the rightmost n chars n < 0 substring(-n) take the string and cut n chars on the left example: string = "abcdefgh" string.rightStr( 2) = "gh" string.rightStr(-3) = "defgh"
      Parameters:
      strWork - the string to work on
      n - number of characters to cut (negative) or retain (positive)
      Returns:
      the modified string
    • tokenize

      public static VString tokenize(String strWork, String delim, boolean delim2token)
      return a vector of individual tokens
      Multiple consecutive delimitors are treated as one (similar to whitespace handling).

      default: tokenize(strWork, delim, false)

      Parameters:
      strWork - the string to tokenize
      delim - the delimiter, if null use whitespace
      delim2token - should a delimiter be a token?
      Returns:
      the vector of strings - never null
    • tokenize

      public static List<String> tokenize(List<String> l, String strIn, String strSep)
      constructs a VString by tokenizing a string
      Parameters:
      strIn - the string to tokenize
      strSep - the list of separator characters - null if whitespace
    • tokenizeBrackets

      public static VString tokenizeBrackets(String strWork, char delimIn, char delimOut)
      tokenize while counting the referenced in and out so that internal tokens are skipped used e.g for "?:" of "()"
      Parameters:
      strWork -
      delimIn - the
      delimOut -
      Returns:
    • hasToken

      public static boolean hasToken(String strWork, String token, String delim, int iSkip)
      check whether a String contains a given token

      default: hasToken(strWork, token, delim, 0)

      Parameters:
      strWork - the string to work on
      token - the token to search for
      delim - the delimiter of the tokens
      iSkip - the number of matching tokens to skip before returning true
      Returns:
      boolean - true if strWork contains token
    • hasToken

      public static boolean hasToken(String[] strWork, String token, int iSkip)
      check whether a vector of Strings contains a given token

      default: hasToken(strWork, token, 0)

      Parameters:
      strWork - the vector of strings string to work on
      token - the token to search for
      iSkip - the number of matching tokens to skip before returning true
      Returns:
      true, if strWork contains token
    • addToken

      public static String addToken(String strWork, String delim, String newToken)
      replace a token in a string
      Parameters:
      strWork - the String to work on
      delim - the delimiter
      newToken - the new token, if null said token is removed
      Returns:
      the modified string
    • removeToken

      public static String removeToken(String strWork, int index, String delim)
      replace a token in a string
      Parameters:
      strWork - the String to work on
      index - index of the token to replace if<0 return from end (e.g. -1 is the last token)
      delim - the delimiter
      Returns:
      the modified string, null if last token was removed
    • replaceToken

      public static String replaceToken(String strWork, String oldToken, String delim, String newToken)
      Parameters:
      strWork -
      oldToken -
      delim -
      newToken -
      Returns:
    • removeToken

      public static String removeToken(String strWork, String oldToken, String delim)
      Parameters:
      strWork -
      oldToken -
      delim -
      newToken -
      Returns:
    • replaceToken

      public static String replaceToken(String strWork, int index, String delim, String newToken)
      replace a token in a string
      Parameters:
      strWork - the String to work on
      index - index of the token to replace if<0 return from end (e.g. -1 is the last token)
      delim - the delimiter
      newToken - the new token, if null said token is removed
      Returns:
      the modified string - never null
    • token

      public static String token(String strWork, int index, String delim)
      get a single token from a String

      default: Token(strWork, index," \t\n")

      Parameters:
      strWork - the String to work on
      index - index of the token to return
      if<0 return from end (e.g. -1 is the last token)
      delim - the delimiter
      Returns:
      the single token (null if no token found)
    • replaceCharSet

      public static String replaceCharSet(String strWork, String charSet, String replaceString, int offset)
      replace any of a set of characters in a given String

      default: replaceCharSet(strWork, c, s, 0)

      Parameters:
      strWork - String to work on
      charSet - characters to replace
      replaceString - String to insert for any character in charSet, if null simply remove all occurrences of any char in charSet
      offset - where to start replacing
      Returns:
      the String with replaced characters
    • replaceChar

      public static String replaceChar(String strWork, char c, String replaceString, int offset)
      replace multiple occurrences of a character in a given String

      default: replaceChar(strWork, c, s, 0)

      Parameters:
      strWork - String to work on
      c - character to replace
      replaceString - String to insert for c, if null simply remove c
      offset -
      Returns:
      the String with replaced characters
    • replaceString

      public static String replaceString(String strWork, String toReplace, String replaceBy)
      replace a string in a given String if the replacement string is contained by the string to replace, recursively replace until no ocurrences of the original remain thus replaceString("a000000", "00", "0") will return "a0" rather than "a000"
      Parameters:
      strWork - String to work on
      toReplace - String to match and replace
      replaceBy - String to insert for toReplace, null if nothing should be inserted
      Returns:
      the String with replaced characters
    • xmlNameEscape

      public static String xmlNameEscape(String strWork)
      Parameters:
      strWork -
      Returns:
      the escaped string
    • extension

      @Deprecated public static String extension(String pathName)
      Deprecated.
      use URLUtil.extension
      the filename extension of pathName
      Parameters:
      pathName -
      Returns:
    • prefix

      @Deprecated public static String prefix(String strWork)
      Deprecated.
      use UrlUtil.prefix(strWork);
      inverse of extension
      Parameters:
      strWork - the string to work on
      Returns:
      the prefix
    • normalize

      public static String normalize(String strWork, boolean toLower)
      normalize a string by stripping and converting any internal whitespace to a single blank
      Parameters:
      strWork - the input
      toLower - if true return all lower case
      Returns:
      the output; null if all characters were removed
    • normalize

      public static String normalize(String strWork)
      normalize a string by stripping and converting any internal whitespace to a single blank
      Parameters:
      strWork - the input
      Returns:
      the output; null if all characters were removed
    • normalize

      public static String normalize(String strWork, boolean toLower, String replace)
      normalize a string by stripping and converting any internal whitespace to the value of replace
      Parameters:
      strWork - the input
      toLower - if true return all lower case
      replace - the replace character, if null remove all whitespace
      Returns:
      the output; null if all characters were removed
    • getDefaultNull

      public static String getDefaultNull(String s, String def)
      return null if s==null or s==def, else s
      used e.g. to zapp "" strings
      Parameters:
      s - the String to test
      def - the default that is converted to null
      Returns:
      the converted String
    • getDistance

      public static int getDistance(String s1, String s2, boolean normalize, boolean ignoreCase, boolean ignoreEmpty, boolean reduceSubstring)
      Parameters:
      s1 -
      s2 -
      normalize -
      ignoreCase -
      ignoreEmpty -
      reduceSubstring - if true slide over the string and check only the substring
      Returns:
    • length

      public static int length(String s1)
    • getDistance

      public static int getDistance(String s1, String s2, boolean normalize, boolean ignoreCase, boolean ignoreEmpty)
      return the Levenschtein ditance where null is treated as ""
      Parameters:
      s1 -
      s2 -
      normalize - if true, normalize strings prior to calculating
      ignoreCase - if true, ignore case strings when calculating
      ignoreEmpty - if true, the result is 0 if one of the two strings is null or ""
      Returns:
      the Levenshtein distance
    • getNonEmpty

      public static String getNonEmpty(String s)
      return null if s==null or s=="", else s
      used e.g. to zapp "" strings
      Parameters:
      s - the String to test
      Returns:
      the converted String
    • isEmpty

      public static boolean isEmpty(String s)
      return true if s==null or s==""
      Parameters:
      s -
      Returns:
    • isEmpty

      public static boolean isEmpty(Collection<String> v)
      are we null or empty or contain only an empty JDFAttributeMap
      Parameters:
      v -
      Returns:
    • hasContent

      public static boolean hasContent(String s)
      return false if s==null or s has only whotespace
      Parameters:
      s -
      Returns:
    • newExtension

      @Deprecated public static String newExtension(String strWork, String newExt)
      Deprecated.
      use UrlUtil.newExtension
      replace the .extension of a file name
      Parameters:
      strWork - the file path
      newExt - the new extension (works with or without the initial "."
      Returns:
      the strWork with a replaced extension
    • xmlNameSpace

      @Deprecated public static String xmlNameSpace(String strWork)
      Deprecated.
      060314 use KElement.xmlnsprefix
      Parameters:
      strWork -
      Returns:
      String
    • mime

      @Deprecated public static String mime(String strWork)
      Deprecated.
      use MimeUtil.getMimeTypeFromExt(strWork);
      get the mime type for a given extension
      Parameters:
      strWork - String to work in
      Returns:
      the mime type
    • isNMTOKEN

      public static boolean isNMTOKEN(String strWork)
      checks whether a string is a NMTOKEN
      Parameters:
      strWork - the string to check
      Returns:
      boolean - true if strWork is a NMTOKEN
    • isID

      public static boolean isID(String strWork)
      checks whether a string is an ID
      Parameters:
      strWork - the string to check
      Returns:
      boolean - true if strWork is an ID
    • isEqual

      public static boolean isEqual(double d1, double d2)
      return true if d1 and d2 are within a range of epsilon or close enough to be serialized identically
      Parameters:
      d1 -
      d2 -
      Returns:
      true if (almost) identical
    • isEqual

      public static boolean isEqual(double d1, double d2, double delta)
      return true if d1 and d2 are within a range of epsilon or close enough to be serialized identically
      Parameters:
      d1 -
      d2 -
      Returns:
      true if (almost) identical
    • compareTo

      public static int compareTo(double d1, double d2)
      return -1 if d1 < d2 , 0 if d1==d2 ; +1 if d1>d2 are within a range of epsilon or close enough to be serialized identically
      Parameters:
      d1 -
      d2 -
      Returns:
      int 1,0 or -1
    • compare

      public static int compare(String c0, String c1, boolean ignoreCase)
      static implementation of compare for any comparable object that gracefully handles null
      null is always the smallest
      Parameters:
      c0 -
      c1 -
      Returns:
      -1 if c0 < c1, 0 if equal, 1 if c0 > c1;
    • isNMTOKENS

      public static boolean isNMTOKENS(String strWork)
      checks whether a string is matches an NMTOKENS list
      Parameters:
      strWork - the string to check
      Returns:
      boolean - true if strWork is an NMTOKENS list
    • isNMTOKENS

      public static boolean isNMTOKENS(String strWork, boolean bID)
      checks whether a string is a NMTOKENS list
      Parameters:
      strWork - the string to check
      bID - if true, also check that each individual token matches the pattern for an ID
      Returns:
      boolean true if strWork is a NMTOKENS list
    • isBoolean

      public static boolean isBoolean(String strWork)
      checks whether a string matches the boolean values "true" or "false"
      Parameters:
      strWork - the string to check
      Returns:
      boolean true if strWork is represents boolean value
    • isDate

      public static boolean isDate(String strWork)
      checks whether a string matches the boolean values "true" or "false"
      Parameters:
      strWork - the string to check
      Returns:
      boolean true if strWork is represents boolean value
    • isNumberList

      public static boolean isNumberList(String strWork)
      checks whether a string matches the boolean values "true" or "false"
      Parameters:
      strWork - the string to check
      Returns:
      boolean true if strWork is represents boolean value
    • getCharset

      public static Charset getCharset(String csName)
      Parameters:
      csName -
      Returns:
    • getDataType

      public static org.cip4.jdflib.util.StringUtil.EDataType getDataType(String s)
      Parameters:
      s -
      Returns:
      null if nulkl, else the datatype
    • isNumber

      public static boolean isNumber(String str)
      checks whether a string is a number
      Parameters:
      str - the string to check
      Returns:
      boolean true if strWork is a number
    • wipeInvalidXML10Chars

      public static String wipeInvalidXML10Chars(String strText, String replace)
      replaces all chars that are not compatible with xml1.0
      Parameters:
      strText - the text to check
      replace - the single char string to replace non xml chars with; if null the non-xml char is simply omitted
      Returns:
      the clean string, may be the same string
    • find_last_not_of

      public static int find_last_not_of(String strWork, String strNotList)
      find the last character in strwork that is not in strNotList
      Parameters:
      strWork - the string to search
      strNotList - the list of characters to ignore
      Returns:
      position of the last matching char, -1 if all strWork only contains chars from strNotList
    • posOfToken

      public static int posOfToken(String strWork, String name, String separator, int iSkip)
      returns the position of the token, if it is in the String.
      The separator is excluded from the tokens. Multiple consecutive separators are treated as one (similar to whitespace handling).
      Parameters:
      strWork - the string to work on
      name - the token to search
      separator - separator
      iSkip - number of tokens to skip before accepting (if 0 -> take the first etc., -1 -> first as well)
      Returns:
      int - 0 based position if the token exists, else -1
    • hasToken

      @Deprecated public static boolean hasToken(String strWork, String token, String delim)
      Deprecated.
      use the 4 parameter version
      check whether a string contains a complete token

      default: hasToken(strWork, token, delim)

      Parameters:
      strWork - the string to work on
      token - the token to search for
      delim - the delimiter of the tokens
      Returns:
      boolean -
    • indexOfToken

      public static int indexOfToken(String strWork, String token, String delim, int start)
      index of a token in a string
      Parameters:
      strWork - the string to work on
      token - the token to search for
      delim - the delimiter of the tokens
      start - position to search in the string
      Returns:
    • numSubstrings

      public static int numSubstrings(String strWork, String subString)
      counts the number of occurrences of subString in String the total number of occurrences is counted, e.g "aaa" contains "aa" twice
      Parameters:
      strWork -
      subString -
      Returns:
      the number of occurrences
    • setRawBytes

      public static String setRawBytes(byte[] buffer, int len)
      set a string to the raw bytes specified in buffer, bypassing all transcoders
      Parameters:
      buffer - the buffer to assign to this
      len -
      Returns:
      the raw string
    • getRawBytes

      public static byte[] getRawBytes(String strUnicode)
      get the raw bytes specified in strUnicode, bypassing all transcoders
      any character values above 255 is truncated (c=c&0xff)
      Parameters:
      strUnicode - the unicode string
      Returns:
      char array of the raw bytes assigned to this
    • setHexBinaryBytes

      public static String setHexBinaryBytes(byte[] buffer, int len)
      get buffer as HexBinary
      any character values above 255 is truncated
      Parameters:
      buffer - the String which you want to encode to HexBinary
      len - the length of the buffer.
      If<0, default is -1. In this case the length of the char array will be used.
      Returns:
      the hexbinary representation
    • getHexBinaryBytes

      public static byte[] getHexBinaryBytes(byte[] unicodeArray)
      Decode a HexBinary encoded byte array back to Unicode
      Parameters:
      unicodeArray - array which stores the HexBinary
      Returns:
      array of byte holding the unicode chars
    • getUTF8Bytes

      public static byte[] getUTF8Bytes(String strUnicode)
      return the UTF8 String strUnicode as Unicode byte array
      Parameters:
      strUnicode - the unicode string to transcode to utf8
      Returns:
      a byte array[] representing the utf-8 code of the input string, null if an error occurred
    • setUTF8String

      @Deprecated public static byte[] setUTF8String(String strUnicode)
      Deprecated.
      use getUTF8Bytes instead
      Parameters:
      strUnicode -
      Returns:
    • getUTF8String

      public static String getUTF8String(byte[] utf8)
      get the unicode string representing the UTF8 representation of the byte buffer fall back on default encoding in case someone accidentally sends in non utf-8
      Parameters:
      utf8 - the utf-8 encoded byte array
      Returns:
      String - the unicode string representation of the utf8 bytes assigned to this, null if an error occurrred
    • formatDouble

      public static String formatDouble(double d)
      returns a formatted double. Truncates to 8 digits after the "."
      If the double is representable as an integer, any ".0" is stripped.
      Parameters:
      d - the double to format
      Returns:
      the formatted string that represents d TBD handle exp format
    • formatInteger

      public static String formatInteger(int i)
      returns a formatted integer, replaces string constants with according int constants
      Parameters:
      i - the integer to format
      Returns:
      the formatted string that represents i
    • formatLong

      public static String formatLong(long i)
      returns a formatted integer, replaces string constants with according int constants
      Parameters:
      i - the integer to format
      Returns:
      the formatted string that represents i
    • isInteger

      public static boolean isInteger(String str)
      checks whether str reprents an integer
      Parameters:
      str - the String to check
      Returns:
      boolean - true if the string represents an integer number
    • isLong

      public static boolean isLong(String str)
      checks whether str reprents an integer
      Parameters:
      str - the String to check
      Returns:
      boolean - true if the string represents an integer number
    • escape

      public static String escape(String strToEscape, String strCharSet, String strEscapeChar, int iRadix, int iEscapeLen, int iEscapeBelow, int iEscapeAbove)
      escape a string by prepending escapeChar and a numerical representation of the string. Characters to be escaped are defined by toEscape, escapeBelow and escapeAbove

      default: escape(String toEscape, null, 0, 0, 0, 256); //Note that an escaped character can't be unescaped without the knowledge of the escapelength

      Parameters:
      strToEscape - the String to escape
      strCharSet - the set of characters that should be escaped eg "äöüß$€"
      strEscapeChar - the character sequence that marks an escape sequence. If null, "\\" is used
      iRadix - the numerical representation base of the escaped chars, e.g. 8 for octal, 16 for hex
      if radix == 0 the escape char is merely inserted in front of the char to escape
      if radix <0 the escape char is replaced by the prefix
      valid radix: -1,0,2,8,10,16
      iEscapeLen - the number of digits per escaped char, not including escapeChar
      iEscapeBelow - all characters with an encoding below escapeBelow should also be escaped, if negative, no lower limit applies
      iEscapeAbove - all characters with an encoding above escapeAbove should also be escaped, if negative, no upper limit applies
      Returns:
      the string where all required sequences have been replaced by their escaped representation
    • equals

      public static boolean equals(String a, String b)
      return true if a equals b or both are null or ""
      Parameters:
      a - String to compare
      b - String to compare
      Returns:
      boolean true if a equals b or both are one of null or ""
    • escape

      public static byte[] escape(byte[] a_toEscape, String strCharSet, String strEscapeChar, int iRadix, int iEscapeLen, int iEscapeBelow, int iEscapeAbove)
      escape a string by prepending escapeChar and a numerical representation of the string. Characters to be escaped are defined by toEscape, escapeBelow and escapeAbove

      default: escape(String toEscape, null, 0, 0, 0, 256); //Note that an escaped character can't be unescaped without the knowledge of the escapelength

      Parameters:
      a_toEscape - the bytes to escape
      strCharSet - the set of characters that should be escaped eg "äöüß$€"
      strEscapeChar - the character sequence that marks an escape sequence. If null, "\\" is used
      iRadix - the numerical representation base of the escaped chars, e.g. 8 for octal, 16 for hex
      if radix == 0 the escape char is merely inserted in front of the char to escape
      if radix <0 the escape char is replaced by the prefix
      valid radix: -1,0,2,8,10,16
      iEscapeLen - the number of digits per escaped char, not including escapeChar
      iEscapeBelow - all characters with an encoding below escapeBelow should also be escaped, if negative, no lower limit applies
      iEscapeAbove - all characters with an encoding above escapeAbove should also be escaped, if negative, no upper limit applies
      Returns:
      the string where all illegal sequences have been replaced by their escaped representation
    • unEscape

      public static String unEscape(String strToUnescape, String strEscapeChar, int iRadix, int escapeLen)
      unescape a String which was escaped with the Java StringUtil.escape method
      Parameters:
      strToUnescape - the String to unescape. For example zz\d6\zzz\c4\\dc\z\d6\\24\\3f\zz@z
      strEscapeChar - the char which indicates a escape sequence "\\" in this case (thats also the default)
      iRadix - the radix of the escape sequenze. 16 in this example.
      escapeLen - the number of digits per escaped char, not including strEscapeChar
      Returns:
      the unescaped String.
    • unEscape

      public static byte[] unEscape(byte[] byteUnEscape, String strEscapeChar, int iRadix, int escapeLen)
      unescape a String which was escaped with the Java StringUtil.escape method
      Parameters:
      byteUnEscape - the bytes to unescape. For example zz\d6\zzz\c4\\dc\z\d6\\24\\3f\zz�z
      strEscapeChar - the char which indicates a escape sequence "\\" in this case (thats also the default)
      iRadix - the radix of the escape sequenze. 16 in this example.
      escapeLen - the number of digits per escaped char, not including strEscapeChar
      Returns:
      the unescaped byte array. zz�zzz��z�$?zz�z in this example
    • vStringToString

      @Deprecated public static String vStringToString(VString vs)
      Deprecated.
      use vs.getString(" ",null,null)
      converts a VString to a single string represents all members of the VString concatenated together
      Parameters:
      vs -
      Returns:
      String - the unicode string representation of the utf8 bytes assigned to this, null if an error occurrred
    • parseDouble

      public static double parseDouble(String s, double def)
      parses a string to double and catches any format exception
      Parameters:
      s - the string to parse
      def - the default to return in case of error
      Returns:
      the parsed double of s
      Since:
      080404 handles "" gracefully
    • parseBoolean

      public static boolean parseBoolean(String s, boolean def)
      parses a string to boolean and catches any format exception "1" and "0" are treated as true and false respectively
      Parameters:
      s - the string to parse
      def - the default to return in case of error
      Returns:
      the parsed boolean of s
      Since:
      080404 handles "" gracefully
    • parseInt

      public static int parseInt(String s, int def)
      parses a string to integer and catches any format exception
      Parameters:
      s - the string to parse
      def - the default to return in case of error
      Returns:
      the parsed double of s
      Since:
      080404 handles "" gracefully
    • parseLong

      public static long parseLong(String s, long def)
      parses a string to long and catches any format exception
      Parameters:
      s - the string to parse
      def - the default to return in case of error
      Returns:
      the parsed double of s
      Since:
      080404 handles "" gracefully
    • uncToUrl

      public static String uncToUrl(String unc, boolean bEscape128)
      Convert a UNC path to a valid file URL or IRL note that some internal functions use network protocol and therefor performance may be non-optimal
      Parameters:
      unc - The UNC string to parse, may also be used for local characters
      bEscape128 - if true, escape non -ascii chars (URI), if false, don't (IRI)
      Returns:
      the URL string
    • pathToName

      public static String pathToName(String pathName)
      gets the file name from a path - regardless of the OS syntax that the path is declared in
      Parameters:
      pathName -
      Returns:
    • underToCamel

      public static String underToCamel(String toConvert)
    • isWindowsLocalPath

      @Deprecated public static boolean isWindowsLocalPath(String pathName)
      Deprecated.
      use UrlUtil.isWindowsLocalPath(pathName);
      Parameters:
      pathName -
      Returns:
    • isUNC

      @Deprecated public static boolean isUNC(String pathName)
      Deprecated.
      use URLUtil.isUNC(pathName)
      Parameters:
      pathName -
      Returns:
    • simpleRegExptoRegExp

      public static String simpleRegExptoRegExp(String simpleRegExp)
      converts a simple regexp to a real regexp
      * --> (.*) (any # of chars)
      . --> \. (literal ".")
      ? --> . (exactly one character) if one of ([|\ is found in the expression we assume it is a real regexp that has already been converted
      Parameters:
      simpleRegExp - the simple regexp
      Returns:
      the converted real regexp
    • simpleRegExptoRegExp

      public static String simpleRegExptoRegExp(String simpleRegExp, boolean alwaysSimple)
      converts a simple regexp to a real regexp
      * --> (.*) (any # of chars)
      . --> \. (literal ".")
      ? --> . (exactly one character) if not alwaysSimple one of ([|\ is found in the expression we assume it is a real regexp that has already been converted
      Parameters:
      simpleRegExp - the simple regexp
      alwaysSimple -
      Returns:
      the converted real regexp
    • matchesSimple

      public static boolean matchesSimple(String str, String regExp)
      match a regular expression using String.matches(), but also catch exceptions and handle simplified regexp. The null expression is assumed to match anything.
      Parameters:
      str - the string to match
      regExp - the expression to match against
      Returns:
      true, if str matches regExp or regexp is empty
    • matchesSimple

      public static boolean matchesSimple(String str, String regExp, boolean alwaysSimple)
      match a regular expression using String.matches(), but also catch exceptions and handle simplified regexp. The null expression is assumed to match anything.
      Parameters:
      str - the string to match
      regExp - the expression to match against
      alwaysSimple - if true - always escape
      Returns:
      true, if str matches regExp or regexp is empty
    • equals

      public static boolean equals(String attribute, String attribute2, double delta)
      simple comparison of strings with some heuristics
      Parameters:
      attribute -
      attribute2 -
      delta - absolute delta of numeric values to be considered equal
      Returns:
    • matches

      public static boolean matches(String str, String regExp)
      match a regular expression using String.matches(), but also catch exceptions
      does NOT handle simplified regexp. The null expression is assumed to match anything.
      Parameters:
      str - the string to match
      regExp - the expression to match against
      Returns:
      true, if str matches regExp or regexp is empty
    • matchesIgnoreCase

      public static boolean matchesIgnoreCase(String str, String regExp)
      match a regular expression using ignoring cases using String.matches(), but also catch exceptions and handle simplified regexp. The null expression is assumed to match anything.
      Parameters:
      str - the string to match
      regExp - the simplified expression to match against
      Returns:
      true, if str matches regExp or regexp is empty
    • matchesIgnoreCase

      public static boolean matchesIgnoreCase(String str, String regExp, boolean alwaysSimple)
      match a regular expression using ignoring cases using String.matches(), but also catch exceptions and handle simplified regexp. The null expression is assumed to match anything.
      Parameters:
      str - the string to match
      regExp - the simplified expression to match against
      alwaysSimple - TODO
      Returns:
      true, if str matches regExp or regexp is empty
    • concatStrings

      public static void concatStrings(VString vS, String appendString)
      add the string appendString to all Strings in VString vs
      Parameters:
      vS - the string vector
      appendString - the string to append
    • concat

      public static String concat(String s1, String s2, String delim)
      Parameters:
      s1 -
      s2 -
      delim -
      Returns:
    • createString

      public static String createString(InputStream is)
      create a string from an input stream
      Parameters:
      is - the input stream
      Returns:
      the string representation
    • getRelativeURL

      @Deprecated public static String getRelativeURL(File f, File baseDir)
      Deprecated.
      use getRelativeURL(File f, File fCWD, boolean bEscape128)
      returns the relative URL of a file relative to the current working directory
      Parameters:
      f - the file to get the relative url for
      baseDir - the file that describes cwd, if null cwd is calculated
      Returns:
    • getRelativeURL

      @Deprecated public static String getRelativeURL(File f, File baseDir, boolean bEscape128)
      Deprecated.
      use URLUtil.getRelativeURL
      returns the relative URL of a file relative to the current workin directory
      Parameters:
      f - the file to get the relative url for
      baseDir - the file that describes cwd, if null cwd is calculated
      bEscape128 - if true, escape > 128 (URL) else retain (IRL)
      Returns:
    • getRelativePath

      @Deprecated public static String getRelativePath(File f, File fCWD)
      Deprecated.
      use URLUtil.getRelativePath(f, fCWD);
      returns the relative URL of a file relative to the current working directory
      this includes escaping of %20 etc.
      Parameters:
      f - the file to get the relative path for
      fCWD - the file that describes cwd, if null cwd is calculated
      Returns:
    • getNamesVector

      @Deprecated public static VString getNamesVector(Class<? extends ValuedEnum> e)
      Deprecated.
      use @see EnumUtil.getNamesVector
      get a vector of names in an iteration
      Parameters:
      e - any member of the enum to iterate over
      Returns:
      VString - the vector of enum names
    • getEnumsVector

      @Deprecated public static Vector<ValuedEnum> getEnumsVector(Class<? extends ValuedEnum> e)
      Deprecated.
      use @se EnumUtil.getEnumsVector
      get a vector of elements in an iteration
      Parameters:
      e - any member of the enum to iterate over
      Returns:
      Vector - the vector of enum instances
    • fileToUrl

      @Deprecated public static String fileToUrl(File f, boolean b)
      Deprecated.
      use UrlUtil.fileToUrl(f, b);
      Parameters:
      f -
      b -
      Returns:
    • stripPrefix

      public static String stripPrefix(String str, String prefix, boolean bIgnoreCase)
      strip a prefix, if it is there else return the string
      Parameters:
      str - the string to strip
      prefix - the prefix to strip
      bIgnoreCase - if true ignore the case of the prefix
      Returns:
    • stripQuote

      public static String stripQuote(String str, String quote, boolean bTrim)
      strip leading and trailing quotes from a string
      Parameters:
      str - the work string
      quote - the quote character
      bTrim - if true, trim whitespace prior to trimming quotes
      Returns:
      the work string trimmed and trailing + leading quote chars removed
    • stripNot

      public static String stripNot(String work, String keepChars)
      returns a new string that has all characters stripped from work that are not in keepChars
      Parameters:
      work -
      keepChars -
      Returns:
    • trim

      public static String trim(String work, String trimChars)
      returns a new string that has all characters trimmed from the front and back of work that are not in trimChars
      Parameters:
      work -
      trimChars - if null - use standard whitespace
      Returns:
      null if no chars left
    • formatDouble

      public static String formatDouble(double value, int precision)
      returns a formatted double. Truncates to @param precision digits after the "."
      If the double is representable as an integer, any ".0" is stripped.
      Parameters:
      value -
      precision - number of digits after the "."
      Returns:
    • index

      public static int index(String in, String search, int i)
      Parameters:
      in -
      search -
      i -
      Returns:
    • normalizeASCII

      public static String normalizeASCII(String urlString)
      Parameters:
      urlString -
      Returns:
    • intern

      public static String intern(String value)