BALL::Substring Class Reference
[String]

#include <BALL/DATATYPE/string.h>

List of all members.


Classes

class  InvalidSubstring
class  UnboundSubstring

Public Member Functions

Constructors and Destructors
 Substring ()
 Substring (const Substring &substring, bool deep=true)
 Substring (const String &string, Index from=0, Size len=String::EndPos) throw (Exception::IndexUnderflow, Exception::IndexOverflow)
virtual ~Substring ()
void destroy ()
virtual void clear ()
Converters
 operator String () const throw (Substring::UnboundSubstring)
String toString () const throw (Substring::UnboundSubstring)
Binding and Unbinding Substrings
Substringbind (const String &string, Index from=0, Size len=String::EndPos) throw (Exception::IndexUnderflow, Exception::IndexOverflow)
Substringbind (const Substring &substring, Index from=0, Size len=String::EndPos) throw (Exception::IndexUnderflow, Exception::IndexOverflow)
void unbind ()
 

unbinds the substring from the string it is bound to


StringgetBoundString ()
 

Return a pointer to the bound String.


const StringgetBoundString () const
 

Retunrs a const pointer to the bound String.


Assignment
void set (const String &string) throw (Substring::UnboundSubstring)
void set (const Substring &s) throw (Substring::UnboundSubstring)
void set (const char *char_ptr, Size size=String::EndPos) throw (Substring::UnboundSubstring, Exception::NullPointer, Exception::SizeUnderflow)
 

Assigns a substring from a char pointer.


const Substringoperator= (const String &string) throw (Substring::UnboundSubstring)
 

String assignment operator.


const Substringoperator= (const Substring &substring) throw (Substring::UnboundSubstring)
 

Substring assignment operator.


const Substringoperator= (const char *char_ptr) throw (Substring::UnboundSubstring, Exception::NullPointer)
 

char pointer assignment operator


Accessors and Mutators
char * c_str () throw (Substring::UnboundSubstring)
 

Return a pointer to the substring's contents.


const char * c_str () const throw (Substring::UnboundSubstring)
 

Return a const pointer to the substring's contents.


Index getFirstIndex () const throw (Substring::UnboundSubstring)
Index getLastIndex () const throw (Substring::UnboundSubstring)
Size size () const
 

Return the substring size.


char & operator[] (Index index) throw (Substring::UnboundSubstring, Exception::IndexUnderflow, Exception::IndexOverflow)
 

Mutable random access to a character of the substring.


char operator[] (Index index) const throw (Substring::UnboundSubstring, Exception::IndexUnderflow, Exception::IndexOverflow)
 

Random access to a character of the substring (const method).


SubstringtoLower () throw (Substring::UnboundSubstring)
 

Converts the substring to lower case characters.


SubstringtoUpper () throw (Substring::UnboundSubstring)
 

Converts the substring to lower case characters.


Predicates
bool isBound () const
 

Return true, if the substring is bound to a String.


bool isEmpty () const
 

Return true, if the substring is empty or unbound.


Debugging and Diagnostics
bool isValid () const
void dump (std::ostream &s=std::cout, Size depth=0) const throw (Substring::UnboundSubstring)
 

Dumps the substring object (including the values of its private members).



Protected Member Functions

void validateRange_ (Index &from, Size &len) const throw (Exception::IndexUnderflow, Exception::IndexOverflow)

Private Attributes

Stringbound_
Index from_
Index to_

Friends

class String
Stream I/O
BALL_EXPORT friend std::ostream & operator<< (std::ostream &s, const Substring &substring)
 

Writes the substring to a stream.



Comparison Operators

BALL_EXPORT friend bool operator== (const String &string, const Substring &substring) throw (Substring::UnboundSubstring)
 

Return true, if the contents of the substring and the string are equal.


BALL_EXPORT friend bool operator!= (const String &string, const Substring &substring) throw (Substring::UnboundSubstring)
 

Return true, if the contents of the substring and the string are not equal.


bool operator== (const Substring &substring) const throw (Substring::UnboundSubstring)
 

returns true, if the contents of the two substrings are equal


bool operator!= (const Substring &substring) const throw (Substring::UnboundSubstring)
 

Return true, if the contents of the two substrings are not equal.


bool operator== (const String &string) const throw (Substring::UnboundSubstring)
 

Return true, if the contents of the substring and the string are equal.


bool operator!= (const String &string) const throw (Substring::UnboundSubstring)
 

Return true, if the contents of the substring and the string are not equal.


bool operator== (const char *char_ptr) const throw (Substring::UnboundSubstring, Exception::NullPointer)
 

Return true, if the contents of the substring are equal to the contents of the C-string.


bool operator!= (const char *char_ptr) const throw (Substring::UnboundSubstring, Exception::NullPointer)
 

Return true, if the contents of the substring are not equal to the contents of the C-string.


bool operator== (char c) const throw (Substring::UnboundSubstring)
 

Return true, if the substring has length 1 and contains the given char.


bool operator!= (char c) const throw (Substring::UnboundSubstring)
 

Return true, if the substring is differnet from the given char.



Detailed Description

A substring class. The Substring class represents an efficient way to deal with substrings of String . Each Substring is bound to an instance of String and is defined by a start and end index. It can be used like a String (with several restrictions) but only affects the given range of the string it is bount to.


Constructor & Destructor Documentation

BALL::Substring::Substring (  ) 

Default constructor. Create an empty string.

BALL::Substring::Substring ( const Substring substring,
bool  deep = true 
)

Copy constructor. Create a substring from another substring.

Parameters:
substring the substring to be copied
deep ignored
BALL::Substring::Substring ( const String string,
Index  from = 0,
Size  len = String::EndPos 
) throw (Exception::IndexUnderflow, Exception::IndexOverflow)

Create a substring from a string and two indices.

Parameters:
string the string the substring is bound to.
from the start index of the substring
len the length of the substring (default EndPos: to the end of the string)
virtual BALL::Substring::~Substring (  )  [virtual]

Destructor. Destruct the substring.


Member Function Documentation

Substring& BALL::Substring::bind ( const Substring substring,
Index  from = 0,
Size  len = String::EndPos 
) throw (Exception::IndexUnderflow, Exception::IndexOverflow)

Bind the substring to the same string another substring is bound to.

Parameters:
substring the substring that is bound to a string
Substring& BALL::Substring::bind ( const String string,
Index  from = 0,
Size  len = String::EndPos 
) throw (Exception::IndexUnderflow, Exception::IndexOverflow)

Bind the substring to a string.

Parameters:
string the string to bind to
from the start position in the string (default is the beginning of the string)
len the substring's length (default is to the end of the string)
const char* BALL::Substring::c_str (  )  const throw (Substring::UnboundSubstring)

Return a const pointer to the substring's contents.

char* BALL::Substring::c_str (  )  throw (Substring::UnboundSubstring)

Return a pointer to the substring's contents.

virtual void BALL::Substring::clear (  )  [virtual]

Clear the substrings contents. Unbind the substring from its string and set the start and the end position to 0.

void BALL::Substring::destroy (  ) 

Clear the substrings contents. Unbind the substring from its string and set the start and the end position to 0.

void BALL::Substring::dump ( std::ostream &  s = std::cout,
Size  depth = 0 
) const throw (Substring::UnboundSubstring)

Dumps the substring object (including the values of its private members).

const String* BALL::Substring::getBoundString (  )  const

Retunrs a const pointer to the bound String.

String* BALL::Substring::getBoundString (  ) 

Return a pointer to the bound String.

Index BALL::Substring::getFirstIndex (  )  const throw (Substring::UnboundSubstring)

Return the first index of the substring. This means the starting point in the bound string.

Index BALL::Substring::getLastIndex (  )  const throw (Substring::UnboundSubstring)

Return the last index of the substring This means the end point in the bound string.

bool BALL::Substring::isBound (  )  const

Return true, if the substring is bound to a String.

bool BALL::Substring::isEmpty (  )  const

Return true, if the substring is empty or unbound.

bool BALL::Substring::isValid (  )  const

Return true, if the string is bound to a string and its indices are valid. Valid indices means that the first index is not greater than the last index, both indices are non-negative and lesser than the size of the bound string.

BALL::Substring::operator String (  )  const throw (Substring::UnboundSubstring)

Convert a substring to a string. Return a copy of the substring's contents.

bool BALL::Substring::operator!= ( char  c  )  const throw (Substring::UnboundSubstring)

Return true, if the substring is differnet from the given char.

bool BALL::Substring::operator!= ( const char *  char_ptr  )  const throw (Substring::UnboundSubstring, Exception::NullPointer)

Return true, if the contents of the substring are not equal to the contents of the C-string.

bool BALL::Substring::operator!= ( const String string  )  const throw (Substring::UnboundSubstring)

Return true, if the contents of the substring and the string are not equal.

bool BALL::Substring::operator!= ( const Substring substring  )  const throw (Substring::UnboundSubstring)

Return true, if the contents of the two substrings are not equal.

const Substring& BALL::Substring::operator= ( const char *  char_ptr  )  throw (Substring::UnboundSubstring, Exception::NullPointer)

char pointer assignment operator

const Substring& BALL::Substring::operator= ( const Substring substring  )  throw (Substring::UnboundSubstring)

Substring assignment operator.

const Substring& BALL::Substring::operator= ( const String string  )  throw (Substring::UnboundSubstring)

String assignment operator.

bool BALL::Substring::operator== ( char  c  )  const throw (Substring::UnboundSubstring)

Return true, if the substring has length 1 and contains the given char.

bool BALL::Substring::operator== ( const char *  char_ptr  )  const throw (Substring::UnboundSubstring, Exception::NullPointer)

Return true, if the contents of the substring are equal to the contents of the C-string.

bool BALL::Substring::operator== ( const String string  )  const throw (Substring::UnboundSubstring)

Return true, if the contents of the substring and the string are equal.

bool BALL::Substring::operator== ( const Substring substring  )  const throw (Substring::UnboundSubstring)

returns true, if the contents of the two substrings are equal

char BALL::Substring::operator[] ( Index  index  )  const throw (Substring::UnboundSubstring, Exception::IndexUnderflow, Exception::IndexOverflow)

Random access to a character of the substring (const method).

char& BALL::Substring::operator[] ( Index  index  )  throw (Substring::UnboundSubstring, Exception::IndexUnderflow, Exception::IndexOverflow)

Mutable random access to a character of the substring.

void BALL::Substring::set ( const char *  char_ptr,
Size  size = String::EndPos 
) throw (Substring::UnboundSubstring, Exception::NullPointer, Exception::SizeUnderflow)

Assigns a substring from a char pointer.

void BALL::Substring::set ( const Substring s  )  throw (Substring::UnboundSubstring)

Copies a substring from another substring

void BALL::Substring::set ( const String string  )  throw (Substring::UnboundSubstring)

Sets the substring to a certain string

Size BALL::Substring::size (  )  const

Return the substring size.

Substring& BALL::Substring::toLower (  )  throw (Substring::UnboundSubstring)

Converts the substring to lower case characters.

String BALL::Substring::toString (  )  const throw (Substring::UnboundSubstring)

Convert a substring to a string. Return a copy of the substring's contents.

Substring& BALL::Substring::toUpper (  )  throw (Substring::UnboundSubstring)

Converts the substring to lower case characters.

void BALL::Substring::unbind (  ) 

unbinds the substring from the string it is bound to

void BALL::Substring::validateRange_ ( Index from,
Size len 
) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) [protected]

Friends And Related Function Documentation

BALL_EXPORT friend bool operator!= ( const String string,
const Substring substring 
) throw (Substring::UnboundSubstring) [friend]

Return true, if the contents of the substring and the string are not equal.

BALL_EXPORT friend std::ostream& operator<< ( std::ostream &  s,
const Substring substring 
) [friend]

Writes the substring to a stream.

BALL_EXPORT friend bool operator== ( const String string,
const Substring substring 
) throw (Substring::UnboundSubstring) [friend]

Return true, if the contents of the substring and the string are equal.

friend class String [friend]

Member Data Documentation