cds.util
Class Strings

java.lang.Object
  extended bycds.util.Strings

public class Strings
extends java.lang.Object

Utility methods for String algorithm

Version:
1.0 May 2002
1.1 Nov 2002 (SJ) : add methods simpleQuote() et bracketsToParentheses()
1.2 May 2003 (MW) : reduce: leave '\' if not followed by a special char 1.3 July 2003 (SJ) : add method isTypeOf 1.4 Jan 2004 (BB) : Ajout d'une methode isUpperString.
Author:
Marc Wenger/CDS

Field Summary
static int CENTER
           
static int JUSTIFY
           
static int LEFT
           
static int RIGHT
           
 
Constructor Summary
Strings()
           
 
Method Summary
static java.lang.String bracketsToParentheses(java.lang.String str)
          Remplacement des crochets par des parentheses dans une chaine de caracteres
static PairInteger delimit(java.lang.String str, int idx)
          Returns a pair of positions in a string which delimit a quoted string.
static java.lang.String duplicate(char c, int n)
          Build a string by duplicating a character x times
static java.lang.String escape(java.lang.String str, char quote)
          Escape all special characters in a string for storage and further re-analysis with delimit() and reduce()
static boolean isTypeOf(java.lang.String str, java.lang.String type)
          Test du type d'une chaine de caracteres (numerique, alphanumerique...)
static boolean isUpperString(java.lang.String string, java.lang.String ignorechars)
          MOD-BB ajout de cette methode; Renvoie vrai si la chaine passee en parametre est en majuscule, faux sinon.
static java.lang.String justify(int dir, int integer, int npos, char fill)
          Returns a string representing an integer number jsutified like specified
static java.lang.String justify(int dir, java.lang.String str, int npos, char fill)
          Returns a string on 'n' character LEFT or RIGHT justified, and filled with a specified character
static void main(java.lang.String[] args)
           
static java.lang.String reduce(java.lang.String str)
          Reduces a String by management of quotes, substitution of \x chars, ...
static java.lang.String reduce(java.lang.String str, int begin, int end)
          Reduces a String by management of quotes, substitution of \x chars, ...
static java.lang.String reduce(java.lang.String str, PairInteger pi)
          Reduces a String by management of quotes, substitution of \x chars, ...
static java.lang.String simpleQuote(java.lang.String str)
          Traitement de l'apostrophe dans la chaine de caracteres Toutes les occurences de ' sont remplacees par \'
static java.lang.String splitText(java.lang.String text, int linesize, int format)
          Split a long text in lines having a maximum size.
static java.lang.String trimchar(java.lang.String str, char c)
          Suppresses beginning, ending and all redundant occurence of a specified character in a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

CENTER

public static final int CENTER
See Also:
Constant Field Values

JUSTIFY

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

Strings

public Strings()
Method Detail

trimchar

public static java.lang.String trimchar(java.lang.String str,
                                        char c)
Suppresses beginning, ending and all redundant occurence of a specified character in a string

Parameters:
str - string to clean up
c - char to eliminate
Returns:
the cleaned string

delimit

public static PairInteger delimit(java.lang.String str,
                                  int idx)
Returns a pair of positions in a string which delimit a quoted string. The string may be single or double quoted. Internal quotes which are doubled or escaped are recognized. If the final quote is absent, the the string is considered to end with the String object.

Parameters:
str - String in which a quoted string is to find
idx - begin index to search for the "string"
Returns:
a PairInteger object containing the positions of the first quote and the the position after the last quote.

reduce

public static java.lang.String reduce(java.lang.String str,
                                      PairInteger pi)
Reduces a String by management of quotes, substitution of \x chars, ...

Parameters:
str - String in which the 'string' to reduce is contained
pi - PairInteger object containing the position of the opening quote and the position of the char after the closing quote
Returns:
the reduced string

reduce

public static java.lang.String reduce(java.lang.String str,
                                      int begin,
                                      int end)
Reduces a String by management of quotes, substitution of \x chars, ...

Parameters:
str - String in which the 'string' to reduce is contained. If the string doesn't begin with a quote, no internal quote management will be performed.
begin - first char of the 'string' (first char, or opening quote if the string is surrounded by quotes)
end - first char after the string (after the last char or the closing quote if it exists)
Returns:
the reduced string

reduce

public static java.lang.String reduce(java.lang.String str)
Reduces a String by management of quotes, substitution of \x chars, ... If the string is between quotes (single or double), beginning and ending spaces are trimmed. If the string is without quotes, all spaces are kept.

Parameters:
str - String to reduce
Returns:
the reduced string

escape

public static java.lang.String escape(java.lang.String str,
                                      char quote)
Escape all special characters in a string for storage and further re-analysis with delimit() and reduce()

Parameters:
str - String to escape
quote - designates the surrounding quote type (single or double). '\0' if none. The same character will be doubled in the string
Returns:
the escaped string (generally larger than the input one)

simpleQuote

public static java.lang.String simpleQuote(java.lang.String str)
Traitement de l'apostrophe dans la chaine de caracteres Toutes les occurences de ' sont remplacees par \'

Parameters:
str - the String to transform
Returns:
the string with escaped quotes

bracketsToParentheses

public static java.lang.String bracketsToParentheses(java.lang.String str)
Remplacement des crochets par des parentheses dans une chaine de caracteres

Parameters:
str - chaine a traiter
Returns:
chaine dont les crochets ont ete remplaces par des parentheses

justify

public static java.lang.String justify(int dir,
                                       int integer,
                                       int npos,
                                       char fill)
Returns a string representing an integer number jsutified like specified

Parameters:
dir - direction of justification (Strings.LEFT, .RIGHT or .CENTER)
integer - the number to convert into a string
npos - number of positions
fill - fill character
Returns:
the string containing the justified number

justify

public static java.lang.String justify(int dir,
                                       java.lang.String str,
                                       int npos,
                                       char fill)
Returns a string on 'n' character LEFT or RIGHT justified, and filled with a specified character

Parameters:
dir - direction of justification (Strings.LEFT, .RIGHT or .CENTER)
str - the string to justify
npos - the total number of positions. If the specified number of positions is not suffisant, the string is returned identical.
fill - the fill character
Returns:
the justified string of size 'npos'

splitText

public static java.lang.String splitText(java.lang.String text,
                                         int linesize,
                                         int format)
Split a long text in lines having a maximum size. Splitting occurs only between words (separated by spaces). The resulting text can have its lines left or right aligned, centered or justified

Parameters:
text - original text to format
linesize - maximum size of each line
format - Strings.LEFT, Strings.RIGHT, Strings.CENTERED or Strings.JUSTIFY
Returns:
the formated text. newlines are included in the string.

duplicate

public static java.lang.String duplicate(char c,
                                         int n)
Build a string by duplicating a character x times

Parameters:
c - char to duplicate
n - number of times
Returns:
String containing 'ccccc' n times

isTypeOf

public static boolean isTypeOf(java.lang.String str,
                               java.lang.String type)
Test du type d'une chaine de caracteres (numerique, alphanumerique...)

Parameters:
str - chaine a tester
type - type a tester
Returns:
vrai si le type de la chaine correspond au type indique en parametre, faux sinon

isUpperString

public static boolean isUpperString(java.lang.String string,
                                    java.lang.String ignorechars)
MOD-BB ajout de cette methode; Renvoie vrai si la chaine passee en parametre est en majuscule, faux sinon.

Parameters:
string - Chaine que l'on veut tester.
Returns:
vrai si la chaine passee en parametre est en majuscule, faux sinon.

main

public static void main(java.lang.String[] args)