HepStrings is a simple string class for C++. Strings have automatic
storage management and value semantics. Copying of the string
contents is common in this implementation.
Author
Dag Bruck
Modified slightly by Leif Lonnblad
Declaration
#include "CLHEP/String/Strings.h"
class HepStrings
Public Member Functions
- Constructor
- inline HepString()
- Constructs empty string.
- Constructor
- HepString(char)
- Constructs string from a character.
- Constructor
- HepString(const char *)
- Constructs string from a character array.
- Constructor
- HepString(int)
- Constructs a string from an integer number.
- Constructor
- HepString(double, unsigned precision = 6)
- Constructs a string from a floating point number.
- Note that the precision argument has no effect for the current
implementation when running with libg++.
- Copy constructor
- HepString(const HepString &)
- Constructs copy of another string.
- Destructor
- inline ~HepString()
- Destroys string, deallocating storage.
- Conversion operator
- inline operator const char * () const
- const char* cast operator. Returns pointer to
the contents of the string.
- =
- HepString & operator = (const HepString &)
- HepString & operator = (const char *)
- HepString & operator = (char)
- Assignment to string.
- +
- HepString operator + (const HepString &)
- HepString operator + (const char *)
- HepString operator + (char)
- Concatenates two strings, or a string with a char.
- +=
- HepString & operator += (const HepString &)
- HepString & operator += (const char *)
- HepString & operator += (char)
- Appends a string or character to string.
- !
- inline HepBoolean operator ! () const
- Returns true if the string is empty.
- ==
- inline HepBoolean operator == (const HepString &) const
- HepBoolean operator == (const char *) const
- Tests for equality.
- !=
- inline HepBoolean operator != (const HepString &) const
- inline HepBoolean operator != (const char *) const
- Tests for inequality.
- ()
- inline char operator () (unsigned) const
- Returns i'th character of string.
- No bounds checking! Strings start at 0 (zero).
- HepString operator () (unsigned start, unsigned n) const
- Returns the substring starting at start which is at
most n characters long.
- Strings start at 0 (zero).
- car
- HepString car() const
- Treating the string as a white-space separated list of sub-string,
return the first sub-string.
- Analogous to the car function in lisp.
- cdr
- HepString cdr() const
- Treating the string as a white-space separated list of sub-string,
return the list after removing the first element.
- Analogous to the cdr function in lisp.
- isEmpty
- inline HepBoolean isEmpty() const
- Returns true if the string is empty.
- index
- inline int index(const HepString &) const
- Returns the first position of a string within the string.
- The first character has index 0.
- inline int index(char) const
- Returns the first position of a character within the string.
- The first character has index 0.
- length
- inline unsigned length() const
- Returns length of string (excluding terminating null).
- lIindex
- inline int lIndex(char) const
- Returns the last position of a character within the string.
- lower
- HepString lower() const
- Returns a string where every upper case letter is converted
lower case, according to ctype(3).
Other characters are copied unchanged.
- toInt
- inline long toInt() const
- Converts string contents to integer.
- toFloat
- inline double toFloat() const
- Converts string contents to double.
- upper
- HepString upper() const
- Returns a string where every lower case letter is converted
to upper case, according to ctype(3).
Other characters are copied unchanged.
Non-Member Functions
- +
- HepString operator + (const char *, const HepString &)
- Concatenation.
- ==
- HepBoolean operator == (const char *, const HepString &)
- Tests for equality.
- !=
- HepBoolean operator != (const char *, const HepString &)
- Test for inequality.
- >>
- istream & operator >> (istream &, HepString &)
- Extracts a string from an input stream. Initial whitespace
is skipped. The string extends until the next whitespace.
- <<
- ostream & operator << (ostream &, const HepString &)
- Inserts a string in the output stream. The same formatting
as for char* takes place.
Example
CLHEP/test/testStrings.cc
1 October 1997
EVC