#ifndef __STRINGS_H

#define __STRINGS_H


#include <iostream.h>


class Strings {  
public:

  enum Directions {left, right, leftAndRight};

  Strings ();
  Strings (char);
  Strings (const char*);
  Strings (const Strings&);
  virtual ~Strings();

  virtual int            beginsWith (const char*) const;
  virtual int            contains (const char) const;
  virtual int            contains (const char*) const;
  virtual int            contains (const Strings&) const;
  virtual unsigned int   count (const char) const;
  virtual int            endsWith (const char*) const;
  virtual int            empty() const;
  virtual int            isAlphabetic() const;
  virtual int            isAlphanumeric() const;
  virtual int            isLowercase() const;
  virtual int            isNumeric() const;
  virtual int            isUppercase() const;
  virtual unsigned int   length() const;
  virtual Strings        lowercaseOf() const;
  virtual int            matches (const char*) const;
  virtual int            matches (const Strings&) const;
  virtual int            soundsLike (const char*) const;
  virtual int            soundsLike (const Strings&) const;
  virtual double         toDouble() const;
  virtual int            toInt() const;
  virtual long           toLong() const;
  virtual Strings        sliceOf (const char delimitor) const;
  virtual Strings        token() const;
  virtual Strings        token (const char delimitor) const;
  virtual Strings        uppercaseOf() const;

  virtual void append (char);
  virtual void append (const char*);
  virtual void append (const Strings&); 
  virtual void append (const int);
  virtual void clear();
  virtual void erase();
  virtual void lowercase();
  virtual void prepend (char);
  virtual void prepend (const char*);
  virtual void prepend (const Strings&);
  virtual void prepend (const int);
  virtual void remove (const char);
  virtual void replace (const char, const char);
  virtual void replace (const char, const char*);
  virtual void replace (const char, const Strings&);
  virtual void reverse();
  virtual void slice (unsigned int, const Directions = left);
  virtual void slice (Strings&, const char delimitor, int removeDelimitor = 0);
  virtual void sliceLeft (Strings&, unsigned int);
  virtual void sliceToken (const unsigned int = 1);
  virtual void sliceToken (const char delimitor, int removeDelimitor = 0);
  virtual void sliceToken (Strings& token);
  virtual void sliceToken (Strings& token, const char delimitor, int removeDelimitor = 0);
  virtual void swap (Strings&);
  virtual void trim (const Directions = leftAndRight);
  virtual void trim (const char, const Directions = leftAndRight);
  virtual void uppercase(); 

  operator const char*() const;
  friend ostream& operator << (ostream&, const Strings&);
  const Strings& operator = (char);
  const Strings& operator = (const char*);
  const Strings& operator = (const Strings&);
  friend Strings operator + (const Strings&, const Strings&);
  friend Strings operator + (const Strings&, const char*);
  friend Strings operator + (const char*, const Strings&);
  friend Strings operator + (const Strings&, const char);
  friend Strings operator + (const char, const Strings&);
  friend Strings operator + (const Strings&, const int);
  friend Strings operator + (const int, const Strings&);
  const Strings& operator += (char);
  const Strings& operator += (const char*);
  const Strings& operator += (const Strings&);
  const Strings& operator += (const int);
  int operator == (const Strings&) const;
  int operator == (const char*) const;
  int operator != (const Strings&) const;
  int operator != (const char*) const;
  int operator <  (const Strings&) const;
  int operator <  (const char*) const; 
  int operator >  (const Strings&) const;
  int operator >  (const char*) const;  
  int operator <= (const Strings&) const;
  int operator <= (const char*) const;  
  int operator >= (const Strings&) const; 
  int operator >= (const char*) const;
  const char& operator [] (const unsigned int) const;

protected:
  
  int     checkMatch (char*, char*) const;
  Strings soundexCodeOf (const char*) const;
  int     soundexNumericOf (const char) const;
  void    sliceLeft (unsigned int);
  void    sliceRight (unsigned int);
  void    trimLeft();
  void    trimRight();
  void    trimLeft (const char);
  void    trimRight (const char);

  char*   theString;
};


#endif



// Copyright (c) 1995-1997 D J Supel and ISX Corporation



// ABSTRACT:

// 

//   The String class provides basic string operations. 

//

// METHODS:

//   

// beginsWith (const char*): Returns true if the prefix of the String 

// exactly matches the client specified character string.

//

//   Example: beginsWith ("hello")       on "hello world"    returns 1;

//   Example: beginsWith ("hello")       on "  hello world"  returns 0;

//   Example: beginsWith ("hello world") on "hello world!!!" returns 1;

//

// isAlphabetic() returns true if all characters in the string are

// alphabetic characters or space characters. empty strings return 

// false.

//

// isAlphanumeric() returns true if all characters in the string are

// alphabetic, numeric, or space characters. empty strings return false.

//

// isLowercase() returns true if all characters in the string are

// lowercase characters or space characters. empty strings return 

// false.

//

// isUppercase() returns true if all characters in the string are

// uppercase characters or space characters. empty strings return 

// false.

//

// isNumeric() returns true if all characters in the string are numbers.

// if any spaces exist, false is returned. punctuation in strings 

// currently fail (eg. "24,888.34"). empty strings return false.

//

// matches (const char* pattern) and matches (const Strings& pattern)

// provide UNIX shell-like pattern matching for ?, [], and *.

//

//   Example: matches ("?b?") on "abc" returns 1.

//   Example: matches ("[abc]*") on "apple" returns 1.

//   Example: matches ("[abc]*") on "cat" returns 1.

//   Example: matches ("[abc]*") on "dog" returns 0.

//

// soundsLike (const char*) and soundsLike (const Strings&) returns

// true if the strings compare equally by 'sound', not 'spelling'.

// The method is based on the "soundex" algorithm so best results

// occur in word comparisions as opposed to sentence/phrases. The

// algorithm is 'English' based.

//

//   Example: soundsLike ("Beatles") on "beedles" returns 1.

//   Example: soundsLike ("Botany Bay") on "Botneebay" returns 1.

//   Example: soundsLike ("Rugby") on "rugbug" returns 0.

//

// sliceOf (const char) : Returns the sequence of characters up to

//   the delimitor. If the delimitor is not found, the original string 

//   is returned.

//

// token() : Returns the first non-space sequence of characters.

//

//   Example: token() on "  hello world!"  returns "hello"

//   Example: token() on "hello"           returns "hello"

//   Example: token() on "  hello   "      returns "hello"

//

// token (const char) : Returns the sequence of characters up to 

// the delimitor. If the delimitor is not found, the original string, 

// less any preceeding blank spaces, is returned.

//

//   Example: token (",") on "  hello world, how"  returns "hello world"

//   Example: token (",") on "hello world"         returns "hello world"

//   Example: token (",") on "   hello world,,, "  returns "hello world"

//

// remove (char): remove ALL occurences of the specified character.

//

//   Example: remove (',') on "12,000"     is set to "12000"

//   Example: remove (',') on "12,000,000" is set to "12000000" 

//

// replace (char old, char new): replace ALL occurences of the old

// character with the new character.

//

//   Example: replace (',', '_') on "12,000"     is set to "12_000"

//   Example: replace (',', '_') on "12,000,000" is set to "12_000_000" 

//

// slice (unsigned int, const Directions): cuts off the number of characters

// specified. The client can specify which side of the string the characters 

// are 'sliced' off.

//

//   Example: slice ((unsigned int)4) on "hello world" returns "o world"

//   Example: slice ((unsigned int)2, Strings::right) on "happy" returns "hap"

//

// sliceToken (unsigned int) : Removes the number of 'tokens' specified and  

// sets the string to the begining of the next token.

//

//   Example: sliceToken()  on "   hello world!"  is set to "world!"

//   Example: sliceToken()  on "   $ world!"      is set to "world!"

//   Example: sliceToken()  on "good-day world!"  is set to "world!"

//   Example: sliceToken(2) on "good day world!"  is set to "world!"

//

// sliceToken (const char, int) : Removes the sequence of characters up 

// to the delimitor, including delimitor if int value is true. If the 

// delimitor is not found, the string is altered by removal of any 

// preceeding blank spaces only.

//

//   Example: sliceToken(",") on    "  hello world, how"   is set to ", how"

//   Example: sliceToken(",", 1) on " hello world, how"    is set to "how"

//   Example: sliceToken(",", 1) on " hello world,,, how"  is set to ",,how"

//

// sliceToken (Strings&) and sliceToken (Strings&, const char, int): Perform

// the same operations as the similar sliceToken methods above except the

// sliced off token is returned to the user. This sliced off token will

// have no white-space to its left or right.

//

// trim(): Removes ALL occurences of white-space. The client can specify 

// from which direction trimming takes place.

//

//   Example: trim()                 on " xyz "  is set to "xyz"

//   Example: trim (Strings::left)   on " xyz "  is set to "xyz "

//   Example: trim (Strings::right)  on " xyz "  is set to " xyz"

//

// trim (const char, const Directions): Removes ALL occurences of the

// specified character. The client can specify from which direction 

// trimming of this character takes place.

//

// EXCEPTIONS:

//

//   None.

//

// EXAMPLES:

//

//   See METHODS.

// 

// LIMITATIONS:

//

//   None.

//

// NOTES:

//  

//   None.

//




syntax highlighted by Code2HTML, v. 0.9.1