Loading...
Searching...
No Matches
BALL::Substring Class Reference
Foundation Classes » General datastructures » Miscellaneous » String

`#include <BALL/DATATYPE/string.h>`

## Classes

class | UnboundSubstring
class | InvalidSubstring

## 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)
virtual | ~Substring ()
void | destroy ()
virtual void | clear ()
Converters
| operator String () const
String | toString () const
Binding and Unbinding Substrings
Substring & | bind (const String &string, Index from=0, Size len=String::EndPos)
Substring & | bind (const Substring &substring, Index from=0, Size len=String::EndPos)
void | unbind ()
| unbinds the substring from the string it is bound to
String * | getBoundString ()
| Return a pointer to the bound String.
const String * | getBoundString () const
| Retunrs a const pointer to the bound String.
Assignment
void | set (const String &string)
void | set (const Substring &s)
void | set (const char *char_ptr, Size size=String::EndPos)
const Substring & | operator= (const String &string)
const Substring & | operator= (const Substring &substring)
const Substring & | operator= (const char *char_ptr)
Accessors and Mutators
char * | c_str ()
const char * | c_str () const
Index | getFirstIndex () const
Index | getLastIndex () const
Size | size () const
| Return the substring size.
char & | operator[] (Index index)
char | operator[] (Index index) const
Substring & | toLower ()
Substring & | toUpper ()
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.

## 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)
BALL_EXPORT friend bool | operator!= (const String &string, const Substring &substring)
bool | operator== (const Substring &substring) const
bool | operator!= (const Substring &substring) const
bool | operator== (const String &string) const
bool | operator!= (const String &string) const
bool | operator== (const char *char_ptr) const
bool | operator!= (const char *char_ptr) const
bool | operator== (char c) const
bool | operator!= (char c) const

## Debugging and Diagnostics

bool | isValid () const
void | dump (std::ostream &s=std::cout, Size depth=0) const
void | validateRange_ (Index &from, Size &len) const

## 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 bound to.

Definition at line 1385 of file string.h.

## Constructor & Destructor Documentation

## Substring() [1/3]

BALL::Substring::Substring | ( |  | ) |

Default constructor. Create an empty string.

## Substring() [2/3]

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

## Substring() [3/3]

BALL::Substring::Substring | ( | const String & | string,
|  | Index | from = 0,
|  | Size | len = String::EndPos )

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)

Exceptions

  Exception::IndexUnderflow | if from < 0
  Exception::IndexOverflow | if from || len >= size()

## ~Substring()

virtual BALL::Substring::~Substring | ( |  | ) |

virtual

Destructor. Destruct the substring.

## Member Function Documentation

## bind() [1/2]

Substring & BALL::Substring::bind | ( | const String & | string,
|  | Index | from = 0,
|  | Size | len = String::EndPos )

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)

Exceptions

  Exception::IndexUnderflow | if index < 0
  Exception::IndexOverflow | if index >= size()

## bind() [2/2]

Substring & BALL::Substring::bind | ( | const Substring & | substring,
|  | Index | from = 0,
|  | Size | len = String::EndPos )

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

Parameters

  substring | the substring that is bound to a string

Exceptions

  Exception::IndexUnderflow | if index < 0
  Exception::IndexOverflow | if index >= size()

## c_str() [1/2]

char * BALL::Substring::c_str | ( |  | ) |

Return a pointer to the substring's contents

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## c_str() [2/2]

const char * BALL::Substring::c_str | ( |  | ) | const

Return a const pointer to the substring's contents

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## clear()

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.

## destroy()

void BALL::Substring::destroy | ( |  | ) |

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

## dump()

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

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## getBoundString() [1/2]

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

Return a pointer to the bound String.

## getBoundString() [2/2]

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

Retunrs a const pointer to the bound String.

## getFirstIndex()

Index BALL::Substring::getFirstIndex | ( |  | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## getLastIndex()

Index BALL::Substring::getLastIndex | ( |  | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## isBound()

bool BALL::Substring::isBound | ( |  | ) | const

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

## isEmpty()

bool BALL::Substring::isEmpty | ( |  | ) | const

Return true, if the substring is empty or unbound.

## isValid()

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.

## operator String()

BALL::Substring::operator String | ( |  | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator!=() [1/4]

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

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator!=() [2/4]

bool BALL::Substring::operator!= | ( | const char * | char_ptr | ) | const

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

Exceptions

  Exception::NullPointer | if delimiters == NULL
  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator!=() [3/4]

bool BALL::Substring::operator!= | ( | const String & | string | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator!=() [4/4]

bool BALL::Substring::operator!= | ( | const Substring & | substring | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator=() [1/3]

const Substring & BALL::Substring::operator= | ( | const char * | char_ptr | ) |

char pointer assignment operator

Exceptions

  Exception::NullPointer | if char_ptr == NULL
  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator=() [2/3]

const Substring & BALL::Substring::operator= | ( | const String & | string | ) |

String assignment operator

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator=() [3/3]

const Substring & BALL::Substring::operator= | ( | const Substring & | substring | ) |

Substring assignment operator

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator==() [1/4]

bool BALL::Substring::operator== | ( | char | c | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator==() [2/4]

bool BALL::Substring::operator== | ( | const char * | char_ptr | ) | const

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

Exceptions

  Exception::NullPointer | if delimiters == NULL
  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator==() [3/4]

bool BALL::Substring::operator== | ( | const String & | string | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator==() [4/4]

bool BALL::Substring::operator== | ( | const Substring & | substring | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator[]() [1/2]

char & BALL::Substring::operator[] | ( | Index | index | ) |

Mutable random access to a character of the substring

Exceptions

  Exception::IndexUnderflow | if index < 0
  Exception::IndexOverflow | if index >= size()
  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator[]() [2/2]

char BALL::Substring::operator[] | ( | Index | index | ) | const

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

Exceptions

  Exception::IndexUnderflow | if index < 0
  Exception::IndexOverflow | if index >= size()
  Substring::UnboundSubstring | if this Substring is not correctly bound

## set() [1/3]

void BALL::Substring::set | ( | const char * | char_ptr,
|  | Size | size = String::EndPos )

Assigns a substring from a char pointer

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound
  Exception::IndexUnderflow |
  Exception::NullPointer | if char_ptr == NULL

## set() [2/3]

void BALL::Substring::set | ( | const String & | string | ) |

Sets the substring to a certain string

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## set() [3/3]

void BALL::Substring::set | ( | const Substring & | s | ) |

Copies a substring from another substring

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## size()

Size BALL::Substring::size | ( |  | ) | const

Return the substring size.

## toLower()

Substring & BALL::Substring::toLower | ( |  | ) |

Converts the substring to lower case characters

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## toString()

String BALL::Substring::toString | ( |  | ) | const

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound Convert a substring to a string. Return a copy of the substring's contents.
  Substring::UnboundSubstring | if this Substring is not correctly bound

## toUpper()

Substring & BALL::Substring::toUpper | ( |  | ) |

Converts the substring to lower case characters

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## unbind()

void BALL::Substring::unbind | ( |  | ) |

unbinds the substring from the string it is bound to

## validateRange_()

void BALL::Substring::validateRange_ | ( | Index & | from,
|  | Size & | len ) const

protected

## Friends And Related Symbol Documentation

## operator!=

BALL_EXPORT friend bool operator!= | ( | const String & | string,
|  | const Substring & | substring )

friend

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## operator<<

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

friend

Writes the substring to a stream.

## operator==

BALL_EXPORT friend bool operator== | ( | const String & | string,
|  | const Substring & | substring )

friend

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

Exceptions

  Substring::UnboundSubstring | if this Substring is not correctly bound

## String

friend class String

friend

Definition at line 1387 of file string.h.