com.izforge.izpack.util
Class StringTool

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

public class StringTool
extends Object

A extended Java Implementation of Pythons string.replace()

Author:
marc.eppelmann@gmx.de

Constructor Summary
StringTool()
          Default Constructor
 
Method Summary
static String escapeSpaces(String aPathString)
          Escapes all white Space Characters
static String getPlatformEncoding()
           
static String listToString(List<?> aStringList)
          Transforms a (Array)List of Strings into a line.separator="\n" separated Stringlist.
static String listToString(List<?> aStringList, String aLineSeparator)
          Transforms a (Array)List of Strings into an aLineSeparator separated Stringlist.
static String normalizePath(String destination)
          Normalizes a mixed Windows/Unix Path.
static String normalizePath(String destination, String fileSeparator)
          Normalizes a Windows or Unix Path.
static String replace(String value, String from, String to)
          Replaces from with to in given String: value
static String replace(String value, String from, String to, boolean aCaseSensitiveFlag)
          Replaces from with to in given String: value
static String replaceOrEscapeAll(String aPathString, String replaceOrEscapeWith, 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 String replaceSpaces(String aPathString, String replaceWith)
          Escapes all white Space Characters
static String replaceSpacesWithMinus(String aPathString)
          Escapes all white Space Characters
static boolean startsWith(String str, String prefix)
          True if a given string starts with the another given String
static boolean startsWithIgnoreCase(String str, String prefix)
          The same as startsWith but ignores the case.
static String stringArrayToSpaceSeparatedString(String[] args)
          Converts an String Array to a space separated String w/o any check
static 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

replace

public static String replace(String value,
                             String from,
                             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 String replace(String value,
                             String from,
                             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 String escapeSpaces(String aPathString)
Escapes all white Space Characters

Parameters:
aPathString -
Returns:

replaceSpacesWithMinus

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

Parameters:
aPathString -
Returns:

replaceSpaces

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

Parameters:
aPathString -
Returns:

replaceOrEscapeAll

public static String replaceOrEscapeAll(String aPathString,
                                        String replaceOrEscapeWith,
                                        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 String normalizePath(String destination,
                                   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 String normalizePath(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 String stringArrayToSpaceSeparatedString(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 String getPlatformEncoding()

UTF16

public static String UTF16()

listToString

public static String listToString(List<?> aStringList)
Transforms a (Array)List of Strings into a line.separator="\n" separated Stringlist.

Parameters:
aStringList -
Returns:
a printable list

listToString

public static String listToString(List<?> aStringList,
                                  String aLineSeparator)
Transforms a (Array)List of Strings into an aLineSeparator separated Stringlist.

Parameters:
aStringList -
Returns:
a printable list

startsWith

public static boolean startsWith(String str,
                                 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(String str,
                                           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


Copyright © 2015. All rights reserved.