Member Functions | |
isNull() length() operator!() operator!=() operator()() operator=() |
operator==() operator[]() start() toLower() toUpper() |
#include <rw/cstring.h> RWCString s("test string"); s(6,3); // "tri"
The class RWCSubString allows some subsection of an RWCString to be addressed by defining a starting position and an extent. For example the 7th through the 11th elements, inclusive, would have a starting position of 7 and an extent of 5. The specification of a starting position and extent can also be done in your behalf by such functions as RWCString::strip() or the overloaded function call operator taking a regular expression as an argument. There are no public constructors -- RWCSubStrings are constructed by various functions of the RWCString class and then destroyed immediately.
A zero length substring is one with a defined starting position and an extent of zero. It can be thought of as starting just before the indicated character, but not including it. It can be used as an lvalue. A null substring is also legal and is frequently used to indicate that a requested substring, perhaps through a search, does not exist. A null substring can be detected with member function isNull(). However, it cannot be used as an lvalue.
None
#include <rw/cstring.h> #include <rw/rstream.h> main(){ RWCString s("What I tell you is true."); // Create a substring and use it as an lvalue: s(19, 0) = "three times "; cout << s << endl; }
Program output:
What I tell you is three times true.
RWCSubString& operator=(const RWCString&);
Assignment from an RWCString. The statements:
RWCString a; RWCString b; ... b(2, 3) = a;
will copy a's data into the substring b(2,3). The number of elements need not match: if they differ, b will be resized appropriately. Sets self's extent to be the length of the assigned RWCString. If self is the null substring, then the statement has no effect. Returns a reference to self.
RWCSubString& operator=(const RWCSubString&);
Assignment from an RWCSubString. The statements:
RWCString a; RWCString b; ... b(2, 3) = a(5,5);
will copy 5 characters of a's data into the substring b(2,3). The number of elements need not match: if they differ, b will be resized appropriately. Sets self's extent to be the extent of the assigned RWCSubString. If self is the null substring, then the statement has no effect. Returns a reference to self.
RWCSubString& operator=(const char*);
Assignment from a character string. Example:
RWCString str("Mary had a lamb"); char dat[] = "Perrier"; str(11,4) = dat; // "Mary had a Perrier"
Note that the number of characters selected need not match: if they differ, str will be resized appropriately. Sets self's extent to be the strlen() of the assigned character string. If self is the null substring, then the statement has no effect. Returns a reference to self.
char& operator[](size_t i); char operator[](size_t i) const;
Returns the ith character of the substring. The first variant can be used as an lvalue, the second cannot. The index i must be between zero and the length of the substring, less one. Bounds checking is performed: if the index is out of range, then an exception of type RWBoundsErr will occur.
char& operator()(size_t i); char operator()(size_t i) const;
Returns the ith character of the substring. The first variant can be used as an lvalue, the second cannot. The index i must be between zero and the length of the substring, less one. Bounds checking is enabled by defining the pre-processor macro RWBOUNDS_CHECK before including <rw/cstring.h>. In this case, if the index is out of range, then an exception of type RWBoundsErr will occur.
RWBoolean isNull() const;
Returns TRUE if this is a null substring.
size_t length() const;
Returns the extent (i.e., length) of the RWCSubString.
RWBoolean operator!() const;
Returns TRUE if this is a null substring.
size_t start() const;
Returns the starting element of the RWCSubString.
void toLower();
Changes all upper-case letters in self to lower-case. Uses the standard C library function tolower().
void toUpper();
Changes all lower-case letters in self to upper-case. Uses the standard C library function toupper().
RWBoolean operator==(const RWCSubString&, const RWCSubString&); RWBoolean operator==(const RWCString&, const RWCSubString&); RWBoolean operator==(const RWCSubString&, const RWCString& ); RWBoolean operator==(const char*, const RWCSubString&); RWBoolean operator==(const RWCSubString&, const char* );
Returns TRUE if the substring is lexicographically equal to the character string or RWCString argument. Case sensitivity is exact.
RWBoolean operator!=(const RWCString&, const RWCString& ); RWBoolean operator!=(const RWCString&, const RWCSubString&); RWBoolean operator!=(const RWCSubString&, const RWCString& ); RWBoolean operator!=(const char*, const RWCString& ); RWBoolean operator!=(const RWCString&, const char* );
Returns the negation of the respective operator==().