com.izforge.izpack.util
Class StringTool

java.lang.Object
  extended by com.izforge.izpack.util.StringTool

public class StringTool
extends java.lang.Object

A extended Java Implementation of Pythons string.replace()

Author:
marc.eppelmann@gmx.de

Constructor Summary
StringTool()
          Default Constructor
 
Method Summary
static java.lang.String escapeSpaces(java.lang.String aPathString)
          Escapes all white Space Characters
static java.lang.String getPlatformEncoding()
           
static void main(java.lang.String[] args)
          Standalone callable Test method
static java.lang.String normalizePath(java.lang.String destination)
          Normalizes a mixed Windows/Unix Path.
static java.lang.String normalizePath(java.lang.String destination, java.lang.String fileSeparator)
          Normalizes a Windows or Unix Path.
static java.lang.String replace(java.lang.String value, java.lang.String from, java.lang.String to)
          Replaces from with to in given String: value
static java.lang.String replace(java.lang.String value, java.lang.String from, java.lang.String to, boolean aCaseSensitiveFlag)
          Replaces from with to in given String: value
static java.lang.String replaceOrEscapeAll(java.lang.String aPathString, java.lang.String replaceOrEscapeWith, java.lang.String[] replaceWhat, boolean escape)
          Replaces all given white Space Characters with the replaceOrEscapeWith or Escapes with replaceOrEscapeWith If true was given as Escape-Flag , the Method escapes each whitespace with the replaceOrEscapeWith + replaceWhat[x] Otherwise the replaces each replaceWhat[x] with the replaceOrEscapeWith.
static java.lang.String replaceSpaces(java.lang.String aPathString, java.lang.String replaceWith)
          Escapes all white Space Characters
static java.lang.String replaceSpacesWithMinus(java.lang.String aPathString)
          Escapes all white Space Characters
static boolean startsWith(java.lang.String str, java.lang.String prefix)
          True if a given string starts with the another given String
static boolean startsWithIgnoreCase(java.lang.String str, java.lang.String prefix)
          The same as startsWith but ignores the case.
static java.lang.String stringArrayListToString(java.util.ArrayList aStringList)
          Transforms a (Array)List of Strings into a line.separator="\n" separated Stringlist.
static java.lang.String stringArrayListToString(java.util.ArrayList aStringList, java.lang.String aLineSeparator)
          Transforms a (Array)List of Strings into an aLineSeparator separated Stringlist.
static java.lang.String stringArrayToSpaceSeparatedString(java.lang.String[] args)
          Converts an String Array to a space separated String w/o any check
static java.lang.String UTF16()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTool

public StringTool()
Default Constructor

Method Detail

main

public static void main(java.lang.String[] args)
Standalone callable Test method

Parameters:
args - Commandline Args

replace

public static java.lang.String replace(java.lang.String value,
                                       java.lang.String from,
                                       java.lang.String to)
Replaces from with to in given String: value

Parameters:
value - original String
from - Search Pattern
to - Replace with this
Returns:
the replaced String

replace

public static java.lang.String replace(java.lang.String value,
                                       java.lang.String from,
                                       java.lang.String to,
                                       boolean aCaseSensitiveFlag)
Replaces from with to in given String: value

Parameters:
value - original String
from - Search Pattern
to - Replace with this
aCaseSensitiveFlag - set to true be case sensitive.
Returns:
the replaced String

escapeSpaces

public static java.lang.String escapeSpaces(java.lang.String aPathString)
Escapes all white Space Characters

Parameters:
apathString -
Returns:

replaceSpacesWithMinus

public static java.lang.String replaceSpacesWithMinus(java.lang.String aPathString)
Escapes all white Space Characters

Parameters:
apathString -
Returns:

replaceSpaces

public static java.lang.String replaceSpaces(java.lang.String aPathString,
                                             java.lang.String replaceWith)
Escapes all white Space Characters

Parameters:
apathString -
Returns:

replaceOrEscapeAll

public static java.lang.String replaceOrEscapeAll(java.lang.String aPathString,
                                                  java.lang.String replaceOrEscapeWith,
                                                  java.lang.String[] replaceWhat,
                                                  boolean escape)
Replaces all given white Space Characters with the replaceOrEscapeWith or Escapes with replaceOrEscapeWith If true was given as Escape-Flag , the Method escapes each whitespace with the replaceOrEscapeWith + replaceWhat[x] Otherwise the replaces each replaceWhat[x] with the replaceOrEscapeWith.

Parameters:
aPathString - The input string in which the white space should be handled.
replaceOrEscapeWith - The Repace or Escape Char Interpreted depended on the escape Flag
replaceWhat - The atring array with the Characters, which should be replaced
escape - The flag, wihch indeicates, how to handle the given replaceOrEscapeWith String.

normalizePath

public static java.lang.String normalizePath(java.lang.String destination,
                                             java.lang.String fileSeparator)
Normalizes a Windows or Unix Path.

Reason: Javas File accepts / or \ for Pathes. Batches or ShellScripts does it not!

TODO: implement support for MAC < MacOSX

Parameters:
destination -
fileSeparator - a target-system fileseparator
Returns:
the normalized path

normalizePath

public static java.lang.String normalizePath(java.lang.String destination)
Normalizes a mixed Windows/Unix Path. Does Only work for Windows or Unix Pathes Reason: Java.File accepts / or \ for Pathes. Batches or ShellScripts does it not!

Parameters:
destination - accepted mixed form by java.File like "C:/a/mixed\path\accepted/by\Java"
Returns:
the normalized Path

stringArrayToSpaceSeparatedString

public static java.lang.String stringArrayToSpaceSeparatedString(java.lang.String[] args)
Converts an String Array to a space separated String w/o any check

Parameters:
args - The StringArray
Returns:
the space separated result.

getPlatformEncoding

public static java.lang.String getPlatformEncoding()

UTF16

public static java.lang.String UTF16()

stringArrayListToString

public static java.lang.String stringArrayListToString(java.util.ArrayList aStringList)
Transforms a (Array)List of Strings into a line.separator="\n" separated Stringlist.

Parameters:
aStringList -
Returns:
a printable list

stringArrayListToString

public static java.lang.String stringArrayListToString(java.util.ArrayList aStringList,
                                                       java.lang.String aLineSeparator)
Transforms a (Array)List of Strings into an aLineSeparator separated Stringlist.

Parameters:
aStringList -
Returns:
a printable list

startsWith

public static boolean startsWith(java.lang.String str,
                                 java.lang.String prefix)
True if a given string starts with the another given String

Parameters:
str - The String to search in
prefix - The string to search for
Returns:
True if str starts with prefix

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String str,
                                           java.lang.String prefix)
The same as startsWith but ignores the case.

Parameters:
str - The String to search in
prefix - The string to search for
Returns:
rue if str starts with prefix