class pstring

Class that handles strings

Public Methods

char* CastToChar()
Conversion to char* (preferably avoided - use with caution)
operator const char* ()
Conversion to const char*
BOOL operator!=( const char *rhs )
un-equality operator for const char*
BOOL operator!=( const pstring &rhs )
un-equality operator for string
pstring operator+( const pstring &rhs )
Concatenation for two strings
pstring& operator+=( const pstring &rhs )
Concatenation operator
pstring& operator=( const char *buffer )
assignment operator for const char*
pstring& operator=( pstring &rhs )
assignment operator for string
BOOL operator==( const char *rhs )
equality operator for const char*
BOOL operator==( const pstring &rhs )
equality operator for string
const char& operator[]( int iPosition )
Subscript operator for R access to characters
char& operator[]( int iPosition )
Subscript operator for R/W access to characters
void print()
Prints out the address, length and value of the string
pstring( const pstring &theString )
copy constructor
pstring( const char *pcString = NULL )
constructor from a const char*
pstring( const long iValue )
constructor from a long value
int size()
Returns the length [in bytes]
~pstring()
destructor

Private Fields

int iLength
length in bytes
char* pcString
the string itself

Private Methods

friend ostream& operator<<( ostream& os, const pstring &theString )
Writes the const string to the ostream - writes "NULL-string" if string is NULL.
friend ostream& operator<<( ostream& os, pstring &theString )
Writes the string to the ostream - writes "NULL-string" if string is NULL.
friend istream& operator>>( istream& is, pstring &theString )
Reads the string from the istream

Documentation

Class that handles strings. The most common operators for strings are implemented. This is by no means a very complete implementation, there surely are lots of commercial solutions around but for now this is good enough for me. In addition one can add all sorts of string manipulations as they are needed.

Comments:

friend ostream& operator<<( ostream& os, pstring &theString )
Writes the string to the ostream - writes "NULL-string" if string is NULL.

friend ostream& operator<<( ostream& os, const pstring &theString )
Writes the const string to the ostream - writes "NULL-string" if string is NULL.

friend istream& operator>>( istream& is, pstring &theString )
Reads the string from the istream. The sequence of characters is first put into an internal (fixed sized) buffer of length MAX_BUFFER_FOR_INPUT_OPERATOR. A message is written to cerr if there is an overflow (which in its current version is not handled).

pstring( const char *pcString = NULL )
constructor from a const char*

pstring( const pstring &theString )
copy constructor

pstring( const long iValue )
constructor from a long value

~pstring()
destructor

pstring& operator=( pstring &rhs )
assignment operator for string

pstring& operator=( const char *buffer )
assignment operator for const char*

BOOL operator==( const pstring &rhs )
equality operator for string

BOOL operator==( const char *rhs )
equality operator for const char*

BOOL operator!=( const pstring &rhs )
un-equality operator for string

BOOL operator!=( const char *rhs )
un-equality operator for const char*

pstring& operator+=( const pstring &rhs )
Concatenation operator

pstring operator+( const pstring &rhs )
Concatenation for two strings. Note that this is a member function, so it won't work if we have a const char* on the left hand side of the + operator [solution would be yet another friend operator, which we don't implement].

char& operator[]( int iPosition )
Subscript operator for R/W access to characters

const char& operator[]( int iPosition )
Subscript operator for R access to characters

operator const char* ()
Conversion to const char*

char* CastToChar()
Conversion to char* (preferably avoided - use with caution)

void print()
Prints out the address, length and value of the string. Format: address in HEX length-in-bytes string. Prints "NULL" if we have the NULL string.

int size()
Returns the length [in bytes]

int iLength
length in bytes

char* pcString
the string itself


This class has no child classes.
Author:
C.Witzig
Date: July 5, 98
Version:
Last update July 5, 98

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de