String Class Reference

SimTK::String is just an std::string with some additional methods defined. More...

#include <String.h>

List of all members.

Public Member Functions

 String ()
 Default constructor produces an empty string.
 String (const char *s)
 This is an implicit conversion from const char* to String.
 String (char c)
 We allow creating a String from a char but you have to do it explicitly.
 String (const std::string &s)
 This is an implicit conversion from std::string to String.
 String (const String &s, int start, int len)
 Construct a String as a copy of a substring begining at position start with length len.
 operator const char * () const
 This is an implicit conversion from String to null-terminated C-style string (array of chars).
char & operator[] (int i)
 Add operator[] that takes int index instead of size_type.
char operator[] (int i) const
 Add operator[] that takes int index instead of size_type.
char & operator[] (std::string::size_type i)
 Pass through to string::operator[].
char operator[] (std::string::size_type i) const
 Pass through to string::operator[].
int size () const
 Override std::string size() method to return an int instead of the inconvenient unsigned type size_type.
int length () const
 Override std::string length() method to return an int instead of the inconvenient unsigned type size_type.
Formatting constructors

These contructors format the supplied argument into a String which is suitable to use with the "<<" stream operator.



 String (int i)
 Format an int as a printable String.
 String (long i)
 Format a long as a printable String.
 String (long long i)
 Format a long long as a printable String.
 String (unsigned int s)
 Format an unsigned int as a printable String.
 String (unsigned long s)
 Format an unsigned long as a printable String.
 String (unsigned long long s)
 Format an unsigned long long as a printable String.
 String (float r)
 Format a float as a printable String.
 String (double r)
 Format a double as a printable String.
 String (long double r)
 Format a long double as a printable String.
 String (std::complex< float > r)
 Format a complex<float> as a printable String (real,imag).
 String (std::complex< double > r)
 Format a complex<double> as a printable String (real,imag).
 String (std::complex< long double > r)
 Format a complex<long double> as a printable String (real,imag).
 String (bool b)
 Format a bool as a printable String "true" or "false".
In-place modifications

These are member functions which add to the existing std::string functionality.

These methods return a reference to "this" String, so may be chained like assignment statements. If you would like to use these on an std::string, use the String::updAs() method to recast the std::string to a String. Note that there is also an equivalent set of static methods which return a new String rather than changing the original.



StringtoUpper ()
 Upshift the given String in place, so that lowercase letters are replaced with their uppercase equivalents as defined by std::toupper().
StringtoLower ()
 Downshift the given String in place, so that uppercase letters are replaced with their lowercase equivalents as defined by std::tolower().
StringtrimWhiteSpace ()
 Trim this String in place, removing all the initial leading and trailing white space, as defined by std::isspace() which typically includes space, tab (\t), newline (\n), return (\r), and form feed (\f).
StringreplaceAllChar (char oldChar, char newChar)
 Substitute in place newChar for oldChar wherever oldChar appears in this String.

Utility methods

These static methods operate on SimTK::String or std::string objects and return SimTK::String objects (which are also std::string objects).



StringreplaceAllChar (const std::string &in, char oldChar, char newChar)
 Copy the input std::string to a new SimTK::String while substituting newChar for oldChar wherever oldChar appears in the input.
static const StringgetAs (const std::string &s)
 Cast an std::string to a SimTK::String without copying; subsequent changes to the std::string will affect the SimTK::String too since it is just a reference to the original std::string.
static StringupdAs (std::string &s)
 Cast a non-const std::string to a non-const SimTK::String without copying; changes made to the SimTK::String will affect the original std::string and vice versa.
static String toUpper (const std::string &in)
 Upshift the given std::string returning a new SimTK::String in which all the letters have been made upper case with toupper().
static String toLower (const std::string &in)
 Downshift the given std::string returning a new SimTK::String in which all the letters have be made lower case with tolower().
static String trimWhiteSpace (const std::string &in)
 Copy the input std::string to a new SimTK::String leaving off all the initial leading and trailing white space, as defined by isspace() which typically includes space, tab (\t), newline (\n), return (\r), and form feed (\f).

Detailed Description

SimTK::String is just an std::string with some additional methods defined.

It may be freely interspersed with std:strings.

Binary compatibility note: while the std::string implementation, like the other std classes, is fully exposed in its header file, we have determined that these classes are stable enough, and that compiler implementators work hard to maintain cross-release stability, that we will assume they are "sufficiently" binary compatible to use them in the SimTK API. So std::string and SimTK::String can be passed through the API interface, and will be binary compatible from release to release of the SimTK Core, provided that the compilers used to compile client and library code are binary compatible with respect to the std::string implementation in the C++ Standard Template Library.


Constructor & Destructor Documentation

String (  )  [inline]

Default constructor produces an empty string.

Referenced by String::replaceAllChar(), String::toLower(), and String::toUpper().

String ( const char *  s  )  [inline]

This is an implicit conversion from const char* to String.

String ( char  c  )  [inline, explicit]

We allow creating a String from a char but you have to do it explicitly.

String ( const std::string &  s  )  [inline]

This is an implicit conversion from std::string to String.

String ( const String s,
int  start,
int  len 
) [inline]

Construct a String as a copy of a substring begining at position start with length len.

String ( int  i  )  [inline, explicit]

Format an int as a printable String.

String ( long  i  )  [inline, explicit]

Format a long as a printable String.

String ( long long  i  )  [inline, explicit]

Format a long long as a printable String.

String ( unsigned int  s  )  [inline, explicit]

Format an unsigned int as a printable String.

String ( unsigned long  s  )  [inline, explicit]

Format an unsigned long as a printable String.

String ( unsigned long long  s  )  [inline, explicit]

Format an unsigned long long as a printable String.

String ( float  r  )  [inline, explicit]

Format a float as a printable String.

String ( double  r  )  [inline, explicit]

Format a double as a printable String.

String ( long double  r  )  [inline, explicit]

Format a long double as a printable String.

String ( std::complex< float >  r  )  [inline, explicit]

Format a complex<float> as a printable String (real,imag).

String ( std::complex< double >  r  )  [inline, explicit]

Format a complex<double> as a printable String (real,imag).

String ( std::complex< long double >  r  )  [inline, explicit]

Format a complex<long double> as a printable String (real,imag).

String ( bool  b  )  [inline, explicit]

Format a bool as a printable String "true" or "false".


Member Function Documentation

static const String& getAs ( const std::string &  s  )  [inline, static]

Cast an std::string to a SimTK::String without copying; subsequent changes to the std::string will affect the SimTK::String too since it is just a reference to the original std::string.

int length (  )  const [inline]

Override std::string length() method to return an int instead of the inconvenient unsigned type size_type.

operator const char * (  )  const [inline]

This is an implicit conversion from String to null-terminated C-style string (array of chars).

char operator[] ( std::string::size_type  i  )  const [inline]

Pass through to string::operator[].

References String::operator[]().

char& operator[] ( std::string::size_type  i  )  [inline]

Pass through to string::operator[].

References String::operator[]().

char operator[] ( int  i  )  const [inline]

Add operator[] that takes int index instead of size_type.

References String::operator[]().

char& operator[] ( int  i  )  [inline]

Add operator[] that takes int index instead of size_type.

Referenced by String::operator[]().

String& replaceAllChar ( const std::string &  in,
char  oldChar,
char  newChar 
) [inline]

Copy the input std::string to a new SimTK::String while substituting newChar for oldChar wherever oldChar appears in the input.

References String::String().

String& replaceAllChar ( char  oldChar,
char  newChar 
)

Substitute in place newChar for oldChar wherever oldChar appears in this String.

int size (  )  const [inline]

Override std::string size() method to return an int instead of the inconvenient unsigned type size_type.

Referenced by Protein::initialize(), and RNA::RNA().

static String toLower ( const std::string &  in  )  [inline, static]

Downshift the given std::string returning a new SimTK::String in which all the letters have be made lower case with tolower().

References String::String().

String& toLower (  ) 

Downshift the given String in place, so that uppercase letters are replaced with their lowercase equivalents as defined by std::tolower().

static String toUpper ( const std::string &  in  )  [inline, static]

Upshift the given std::string returning a new SimTK::String in which all the letters have been made upper case with toupper().

References String::String().

String& toUpper (  ) 

Upshift the given String in place, so that lowercase letters are replaced with their uppercase equivalents as defined by std::toupper().

static String trimWhiteSpace ( const std::string &  in  )  [static]

Copy the input std::string to a new SimTK::String leaving off all the initial leading and trailing white space, as defined by isspace() which typically includes space, tab (\t), newline (\n), return (\r), and form feed (\f).

String& trimWhiteSpace (  ) 

Trim this String in place, removing all the initial leading and trailing white space, as defined by std::isspace() which typically includes space, tab (\t), newline (\n), return (\r), and form feed (\f).

static String& updAs ( std::string &  s  )  [inline, static]

Cast a non-const std::string to a non-const SimTK::String without copying; changes made to the SimTK::String will affect the original std::string and vice versa.


The documentation for this class was generated from the following file:

Generated on Wed Dec 30 11:05:28 2009 for SimTKcore by  doxygen 1.6.1