Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.rgw.tools
Class StringTool

java.lang.Object
  extended by ch.rgw.tools.StringTool

public class StringTool
extends java.lang.Object

Einige Hilfsfunktionen mit und an Strings und String-Collections

Author:
Gerry Weirich

Nested Class Summary
static interface StringTool.flattenFilter
           
static class StringTool.tokenizer
          Dem StreamTokenizer nachempfundene Klasse, die auf einem String arbeitet.
 
Field Summary
static java.lang.String backslash
           
static int BZIP
           
static java.lang.String crlf
           
static java.lang.String equals
           
static java.lang.String flattenSeparator
           
static int GLZ
           
static int GUESS
           
static int HUFF
           
static java.lang.String ipv4address
           
static java.lang.String ipv6address
           
static java.lang.String leer
           
static int LEFT
           
static java.lang.String lf
           
static java.lang.String lineSeparators
           
static int NONE
           
static java.lang.String numbers
           
static int RIGHTS
           
static java.lang.String slash
           
static java.lang.String space
           
static java.lang.String wordChars
           
static java.lang.String wordSeparatorChars
           
static java.lang.String wordSeparators
           
static int ZIP
           
 
Constructor Summary
StringTool()
           
 
Method Summary
static java.lang.String addModulo10(java.lang.String number)
          Eine beliebige Ziffernfolge mit der Modulo-10 Prüfsumme verpacken
static java.lang.String capitalize(java.lang.String orig)
          Convert first Character to uppercase. leave rest unchanged
static java.lang.String checkModulo10(java.lang.String number)
          Die Modulo-10-Prüfsumme wieder entfernen
static boolean compare(byte[] a, byte[] b)
          Verleicht zwei byte-Arrays
static int compareWithNull(java.lang.String a, java.lang.String b)
          Zwei Strings verleichen.
static java.lang.String[] convertEncoding(java.lang.String[] src, java.lang.String srcEncoding)
          convert a String Array from a source encoding to this platform's default encoding
static java.lang.String convertEncoding(java.lang.String src, java.lang.String srcEncoding)
          convert a String from a source encoding to this platform's default encoding
static java.lang.String createString(byte[] bytes)
          create a String from a byte array, using the configured charset (defaults to utf-8)
static byte[] dePrintable(java.lang.String src)
          Wandelt einen mit enPrintable erhaltenen String in ein byte-Array zurück.
static byte[] dePrintable(java.lang.String src, int offset)
           
static byte[] dePrintableStrict(java.lang.String src)
          Convert a String that was created with enPrintableStrict() back into a byte array
static void dumpHashtable(Log log, java.util.Hashtable table)
           
static java.lang.String enPrintable(byte[] src)
          Wandelt ein Byte-Array in einen druckbaren String um.
static java.lang.String enPrintable(byte[] src, int offset)
           
static java.lang.String enPrintableStrict(byte[] src)
          Convert a byte array into a String that consists strictly only of numbers and capital Letters.
static java.lang.String filler(java.lang.String str, int num)
          Erstellt einen String aus mehreren nacheinander folgenden Strings
static byte[] flatten(java.util.Hashtable hash, int compressMode, java.lang.Object ExtInfo)
          Deprecated. compressmode is always ZIP now.
static java.lang.String flattenStrings(java.util.Hashtable h)
          Wandelt eine Hashtable in einen String aus Kommagetrennten a=b-Paaren um.
static java.lang.String flattenStrings(java.util.Hashtable<java.lang.Object,java.lang.Object> h, StringTool.flattenFilter fil)
           
static java.util.Hashtable fold(byte[] flat, int compressMode, java.lang.Object ExtInfo)
          Deprecated. 
static java.util.Hashtable foldStrings(java.lang.String s)
           
static byte[] getBytes(java.lang.String string)
          Create a byte arra from a String using the configured charset (defaults to utf-8)
static java.lang.String getDefaultCharset()
          get the configured default charset
static java.lang.String getFirstLine(java.lang.String in, int maxChars)
          Return the first line if the given String but at most maxChars
static java.lang.String getFirstWord(java.lang.String in)
          Return the first word of the given String
static int getIndex(java.lang.String[] arr, java.lang.String val)
          Sucht einen String in einem String-Array und gibt dessen Index zurück.
static java.lang.String getSafe(java.lang.String[] array, int index)
          String aus einem Array holen.
static java.awt.geom.Rectangle2D getStringBounds(java.lang.String s, java.awt.Graphics g)
          Deprecated. this ist a dependency to Swing
static java.lang.String getWordAtIndex(java.lang.String text, int index)
          Gibt das Wort des Inhalts zurück das an oder unmittelbar vor der angegebenen Position ist
static boolean isEmpty(java.lang.String[] f)
          Gibt true zurück, wenn das Feld null ist, leer ist, oder nur Leerstrings enthält
static boolean isFemale(java.lang.String name)
          Versucht herauszufinden, ob ein Name weiblich ist
static boolean isIPAddress(java.lang.String in)
          Test whether a String is an IPV4 or IPV6-Address
static boolean isMailAddress(java.lang.String in)
           
static boolean isNothing(java.lang.Object n)
          gibt true zurück, wenn das Objekt kein String oder null oder "" ist
static java.lang.String join(java.lang.Iterable<java.lang.String> i, java.lang.String tren)
           
static java.lang.String join(java.lang.String[] arr, java.lang.String tren)
          Verknüpft die Elemente eines String-Arrays mittels tren zu einem String
static java.lang.String limitLength(java.lang.String orig, int len)
          String wenn nötig kürzen
static java.lang.String maskHTML(java.lang.String input)
          Make a String XML- rd HTML-ready, i.e. replace all non-xml-characters with entity sequences
static java.lang.String normalizeCase(java.lang.String orig)
          Change first lettere to uppercase, other letters to lowercase
static byte[] pack(java.util.Collection<java.lang.String> strings)
          Eine String-Collection comprimieren
static byte[] pack(java.lang.String[] strings)
          compress an array of single-lined Strings into a byte array
static java.lang.String pad(int where, char chr, java.lang.String src, int size)
          Verlängert oder kürzt einen String.
static double parseSafeDouble(java.lang.String string)
          Parse a Double from a string but don't throw an Exception if not parseable.
static int parseSafeInt(java.lang.String string)
          Parse a String but don't throw expetion if not parsable.
static java.lang.String RectangleToString(int x, int y, int w, int h)
           
static void setDefaultCharset(java.lang.String charset_name)
          Set the charset to use in all charset-dependent String operations
static java.lang.String[] split(java.lang.String m, java.lang.String delim)
          Deprecated. obsoleted by java 1.4x 's String.split method.
static java.util.List<java.lang.String> splitAL(java.lang.String m, java.lang.String delim)
          Split a String into an ArrayList
static java.util.Vector splitV(java.lang.String m, java.lang.String delim)
          Spaltet einen String in einen Vektor
static java.lang.String unambiguify(java.lang.String in)
          String mit unterschiedlicher möglicher Schreibweise in einheitliche Schreibweise bringen
static java.lang.String unique(java.lang.String salt)
          Gibt eine zufällige und eindeutige Zeichenfolge zurück
static java.lang.String unNull(java.lang.String in)
          make sure a String is never null
static java.util.List<java.lang.String> unpack(byte[] pack)
          Unpack a Zip-compressed byte-Array in a List of Strings.
static java.lang.String Version()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

leer

public static final java.lang.String leer
See Also:
Constant Field Values

space

public static final java.lang.String space
See Also:
Constant Field Values

equals

public static final java.lang.String equals
See Also:
Constant Field Values

crlf

public static final java.lang.String crlf
See Also:
Constant Field Values

lf

public static final java.lang.String lf
See Also:
Constant Field Values

slash

public static final java.lang.String slash
See Also:
Constant Field Values

backslash

public static final java.lang.String backslash
See Also:
Constant Field Values

numbers

public static final java.lang.String numbers
See Also:
Constant Field Values

wordSeparatorChars

public static final java.lang.String wordSeparatorChars
See Also:
Constant Field Values

wordSeparators

public static final java.lang.String wordSeparators
See Also:
Constant Field Values

lineSeparators

public static final java.lang.String lineSeparators
See Also:
Constant Field Values

ipv4address

public static final java.lang.String ipv4address
See Also:
Constant Field Values

ipv6address

public static final java.lang.String ipv6address
See Also:
Constant Field Values

wordChars

public static final java.lang.String wordChars
See Also:
Constant Field Values

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHTS

public static final int RIGHTS
See Also:
Constant Field Values

flattenSeparator

public static final java.lang.String flattenSeparator
See Also:
Constant Field Values

NONE

public static final int NONE
See Also:
Constant Field Values

HUFF

public static final int HUFF
See Also:
Constant Field Values

BZIP

public static final int BZIP
See Also:
Constant Field Values

GLZ

public static final int GLZ
See Also:
Constant Field Values

ZIP

public static final int ZIP
See Also:
Constant Field Values

GUESS

public static final int GUESS
See Also:
Constant Field Values
Constructor Detail

StringTool

public StringTool()
Method Detail

Version

public static final java.lang.String Version()

setDefaultCharset

public static void setDefaultCharset(java.lang.String charset_name)
Set the charset to use in all charset-dependent String operations

Parameters:
charset_name - the name of the charset (that must be valid)

getDefaultCharset

public static java.lang.String getDefaultCharset()
get the configured default charset

Returns:
the charset name (defaults to utf-8)

createString

public static java.lang.String createString(byte[] bytes)
create a String from a byte array, using the configured charset (defaults to utf-8)

Parameters:
bytes - an array of bytes rthat constitute a String in the indicated charset.
Returns:
the created String.

getBytes

public static byte[] getBytes(java.lang.String string)
Create a byte arra from a String using the configured charset (defaults to utf-8)

Parameters:
string -
Returns:

getStringBounds

@Deprecated
public static java.awt.geom.Rectangle2D getStringBounds(java.lang.String s,
                                                                   java.awt.Graphics g)
Deprecated. this ist a dependency to Swing

return the bounds of a Rectangle around a String


split

@Deprecated
public static java.lang.String[] split(java.lang.String m,
                                                  java.lang.String delim)
Deprecated. obsoleted by java 1.4x 's String.split method.

Split a String into a String Arry


splitV

public static java.util.Vector splitV(java.lang.String m,
                                      java.lang.String delim)
Spaltet einen String in einen Vektor

Parameters:
m - der zu splittende String
delim - Trennzeichen, an dem zu splitten ist.

splitAL

public static java.util.List<java.lang.String> splitAL(java.lang.String m,
                                                       java.lang.String delim)
Split a String into an ArrayList

Parameters:
m - the String to msplit
delim - the delimiter to split at
Returns:
an ArrayList containing at least one element without the delimiter

flattenStrings

public static java.lang.String flattenStrings(java.util.Hashtable h)
Wandelt eine Hashtable in einen String aus Kommagetrennten a=b-Paaren um.


flattenStrings

public static java.lang.String flattenStrings(java.util.Hashtable<java.lang.Object,java.lang.Object> h,
                                              StringTool.flattenFilter fil)

pack

public static byte[] pack(java.util.Collection<java.lang.String> strings)
Eine String-Collection comprimieren

Parameters:
strings -
compressMode -
Returns:
ein byte array mit dem komprimierten Inhalt der String-Collection

pack

public static byte[] pack(java.lang.String[] strings)
compress an array of single-lined Strings into a byte array

Parameters:
strings - an array of String that must not contain newline (\n) characters
Returns:
a byte array with the ZIP-compressed contents of the String array

unpack

public static java.util.List<java.lang.String> unpack(byte[] pack)
Unpack a Zip-compressed byte-Array in a List of Strings.

Parameters:
pack - a packed byte array as created by pack()
Returns:
an ArrayList of Strings
See Also:
pack(String[]), pack(Collection)

flatten

@Deprecated
public static byte[] flatten(java.util.Hashtable hash,
                                        int compressMode,
                                        java.lang.Object ExtInfo)
Deprecated. compressmode is always ZIP now.

Eine Hashtable in ein komprimiertes Byte-Array umwandeln

Parameters:
hash - die Hashtable
compressMode - GLZ, HUFF, BZIP2
ExtInfo - Je nach Kompressmode nötige zusatzinfo
Returns:
das byte-Array mit der komprimierten Hashtable

fold

@Deprecated
public static java.util.Hashtable fold(byte[] flat,
                                                  int compressMode,
                                                  java.lang.Object ExtInfo)
Deprecated. 

Ein mit flatten() erzeugtes Byte-Array wieder in eine HAshtable zurückverwandeln

Parameters:
flat - Die komprimierte Hashtable
compressMode - Expnad-Modus
ExtInfo -
Returns:
die Hastbale

foldStrings

public static java.util.Hashtable foldStrings(java.lang.String s)

isNothing

public static boolean isNothing(java.lang.Object n)
gibt true zurück, wenn das Objekt kein String oder null oder "" ist


isEmpty

public static boolean isEmpty(java.lang.String[] f)
Gibt true zurück, wenn das Feld null ist, leer ist, oder nur Leerstrings enthält


compare

public static boolean compare(byte[] a,
                              byte[] b)
Verleicht zwei byte-Arrays


getIndex

public static int getIndex(java.lang.String[] arr,
                           java.lang.String val)
Sucht einen String in einem String-Array und gibt dessen Index zurück. Die Suche erfolgt ohne Berücksichtigung von Gross/Kleinschreibung.

Returns:
den index von val in arr oder -1 wenn nicht gefunden.

pad

public static java.lang.String pad(int where,
                                   char chr,
                                   java.lang.String src,
                                   int size)
Verlängert oder kürzt einen String.

Parameters:
where - LEFT vorne füllen, RIGHT hinten füllen
chr - Zeichen zum Füllen
src - Quellstring
size - erwünschte Länge
Returns:
der neue String

filler

public static java.lang.String filler(java.lang.String str,
                                      int num)
Erstellt einen String aus mehreren nacheinander folgenden Strings

Parameters:
str - der zu multiplizierende string
num - Zahl der Multiplikationen

RectangleToString

public static java.lang.String RectangleToString(int x,
                                                 int y,
                                                 int w,
                                                 int h)

join

public static java.lang.String join(java.lang.String[] arr,
                                    java.lang.String tren)
Verknüpft die Elemente eines String-Arrays mittels tren zu einem String

Parameters:
arr - - String Array
tren - - Verbindingsstring
Returns:
den verknüpften String

join

public static java.lang.String join(java.lang.Iterable<java.lang.String> i,
                                    java.lang.String tren)

enPrintable

public static java.lang.String enPrintable(byte[] src)
Wandelt ein Byte-Array in einen druckbaren String um. (Alle Bytes werden in ihre Nibbles zerlegt, diese werden ähnlich wie mit base64 als Zeichen gespeichert


enPrintable

public static java.lang.String enPrintable(byte[] src,
                                           int offset)

dePrintable

public static byte[] dePrintable(java.lang.String src)
Wandelt einen mit enPrintable erhaltenen String in ein byte-Array zurück.


dePrintable

public static byte[] dePrintable(java.lang.String src,
                                 int offset)

enPrintableStrict

public static java.lang.String enPrintableStrict(byte[] src)
Convert a byte array into a String that consists strictly only of numbers and capital Letters. This can be useful for transmission over 7-Bit-Channels (In fact, 4 bit channels would suffice) or Web Forms that would need URLConversion otherwise.

Parameters:
src - the source array
Returns:
a String that is 2 times the length of src + 3 Bytes and consists only of [0-9A-P]*

dePrintableStrict

public static byte[] dePrintableStrict(java.lang.String src)
Convert a String that was created with enPrintableStrict() back into a byte array

Parameters:
src - a String previously created by enPrintableStrict
Returns:
a byte array with the original data or null on errors

unique

public static java.lang.String unique(java.lang.String salt)
Gibt eine zufällige und eindeutige Zeichenfolge zurück

Parameters:
salt - Ein beliebiger String oder null

unNull

public static java.lang.String unNull(java.lang.String in)
make sure a String is never null

Parameters:
in - a String or null
Returns:
"" if in was null, in otherwise

isFemale

public static boolean isFemale(java.lang.String name)
Versucht herauszufinden, ob ein Name weiblich ist

Parameters:
name - der Name
Returns:
true wenn der Name vielleicht weiblich ist

isMailAddress

public static boolean isMailAddress(java.lang.String in)

isIPAddress

public static boolean isIPAddress(java.lang.String in)
Test whether a String is an IPV4 or IPV6-Address

Parameters:
in - a String that is possibly an ipv4 or ipv6-Address
Returns:
true if ir seems to be an IP-Address

getFirstWord

public static java.lang.String getFirstWord(java.lang.String in)
Return the first word of the given String


getFirstLine

public static java.lang.String getFirstLine(java.lang.String in,
                                            int maxChars)
Return the first line if the given String but at most maxChars


getWordAtIndex

public static java.lang.String getWordAtIndex(java.lang.String text,
                                              int index)
Gibt das Wort des Inhalts zurück das an oder unmittelbar vor der angegebenen Position ist

Returns:
Das mit an dieser Stelle befindliche Wort des Strings, String.empty falls kein Wort dort ist idt oder der Index ausserhalb des Textbereichs ist

dumpHashtable

public static void dumpHashtable(Log log,
                                 java.util.Hashtable table)

normalizeCase

public static java.lang.String normalizeCase(java.lang.String orig)
Change first lettere to uppercase, other letters to lowercase

Parameters:
orig - the word to change (at least 2 characters)
Returns:
the normalized word. Tis will return orig if orig is less than 2 characters

capitalize

public static java.lang.String capitalize(java.lang.String orig)
Convert first Character to uppercase. leave rest unchanged

Parameters:
orig - the original String
Returns:
the original String with first Character uppercase

compareWithNull

public static int compareWithNull(java.lang.String a,
                                  java.lang.String b)
Zwei Strings verleichen. Berücksichtigen, dass einer oder beide auch Null sein könnten.

Parameters:
a - erster String
b - zweiter String
Returns:
-1,0 oder 1

limitLength

public static java.lang.String limitLength(java.lang.String orig,
                                           int len)
String wenn nötig kürzen

Parameters:
orig - Originalstring
len - maximal zulöässige Lenge
Returns:
den String, der maximal len Zeichen lang ist

getSafe

public static java.lang.String getSafe(java.lang.String[] array,
                                       int index)
String aus einem Array holen. Leerstring, wenn der angeforderte Index ausserhalb des Arrays liegt

Parameters:
array -
index -
Returns:

parseSafeInt

public static int parseSafeInt(java.lang.String string)
Parse a String but don't throw expetion if not parsable. Return 0 instead

Parameters:
string -
Returns:

parseSafeDouble

public static double parseSafeDouble(java.lang.String string)
Parse a Double from a string but don't throw an Exception if not parseable. Return 0.0 instead.

Parameters:
string - a String containing probably a Double
Returns:
always a double. 0.0 if the origin was 0.0 or null or not a Double

unambiguify

public static java.lang.String unambiguify(java.lang.String in)
String mit unterschiedlicher möglicher Schreibweise in einheitliche Schreibweise bringen

Parameters:
in - ein String
Returns:
derselbe String, aber alle möglicherweise kritische Zeichen durch _ ersetzt.

convertEncoding

public static java.lang.String convertEncoding(java.lang.String src,
                                               java.lang.String srcEncoding)
convert a String from a source encoding to this platform's default encoding

Parameters:
src - the source string
srcEncoding - the name of the encoding of the source
Returns:
the transcoded String or the source String if the encoding is not supported

convertEncoding

public static java.lang.String[] convertEncoding(java.lang.String[] src,
                                                 java.lang.String srcEncoding)
convert a String Array from a source encoding to this platform's default encoding

Parameters:
src - the source Array
srcEncoding - the name of the encoding of the source
Returns:
the transcoded Array or the source Array if the encoding is not supported

maskHTML

public static java.lang.String maskHTML(java.lang.String input)
Make a String XML- rd HTML-ready, i.e. replace all non-xml-characters with entity sequences

Parameters:
input -
Returns:
a string that does not contain any <, > or & characters

addModulo10

public static java.lang.String addModulo10(java.lang.String number)
Eine beliebige Ziffernfolge mit der Modulo-10 Prüfsumme verpacken

Parameters:
number - darf nur aus Ziffern bestehen
Returns:
die Eingabefolge, ergänzt um ihre Prüfziffer

checkModulo10

public static java.lang.String checkModulo10(java.lang.String number)
Die Modulo-10-Prüfsumme wieder entfernen

Parameters:
number - eine um eine prüfziffer ergänzte Zahl
Returns:
die Zahl ohne prüfziffer oder null, wenn die Prüfziffer falsch war.

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis