Module: Essential Tools Module Group: String Processing Classes
Does not inherit
#include <rw/cstring.h> RWCString s("test string"); s(6,3); // "tri"
The class RWCConstSubString 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 is also done on your behalf by such functions as RWCString::strip(). There are no public constructors other than one that creates an RWCConstSubString from an existing RWCSubString. In general, RWCConstSubStrings are constructed by various functions of the RWCConstSubString 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.
Note that RWCConstSubString is only available with the alternate implementation of RWCString. When building on top of a compliant standard library, RWCString uses an alternate implementation that is a thin wrapper on top of std::string. The RWCString interface remains the same, with the addition of this method for easy conversion:
std::string std();
and other overloads on std::string. For applications doing many RWCString->std::string conversions, significant speed improvements might be obtained by using the RWCString standard library implementation.
None
#include <iostream> #include <rw/cstring.h> int main() { const RWCString s ("What I tell you is true."); std::cout << "Take the string: [" << s << "]\n"; // Create a string from substrings: const RWCString s2 (s(0, 16) + "three times " + s(16, 8)); std::cout << "After creating a string from substrings, you have: [" << s2 << "]" << std::endl; return 0; }
Program output:
Take the string: [What I tell you is true.] After creating a string from substrings, you have: [What I tell you three times is true.]
RWCConstSubString(const RWCSubString& sp);
Construct an RWCConstSubString from an existing RWCSubString.
RWCConstSubString(const RWCConstSubString& sp);
Copy constructor. The created string will copy sp's data.
char operator[](size_t i) const;
Return the ith character of the substring. 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) const;
Return the ith character of the substring. The index i must be between zero and the length of the substring, less one. Optional 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.
bool isNull() const;
Return true if this is a null substring.
size_t length() const;
Return the extent (that is, length) of the RWCConstSubString.
bool operator!() const;
Return true if this is a null substring.
size_t start() const;
Return the starting element of the RWCConstSubString.
bool operator==(const RWCConstSubString&, const RWCConstSubString&); bool operator==(const RWCString&, const RWCConstSubString&); bool operator==(const RWCConstSubString&, const RWCString& ); bool operator==(const RWCConstSubString&, const RWCSubString& ); bool operator==(const char*,const RWCConstSubString&); bool operator==(const RWCConstSubString&, const char*);
Returns true if the substring is lexicographically equal to the character string or RWCString argument. Case sensitivity is exact.
bool operator!=(const RWCString&, const RWCConstSubString&); bool operator!=(const RWCConstSubString&, const RWCString&); bool operator!=(const char*, const RWCConstSubString&); bool operator!=(const RWCConstSubString&, const char*);
Returns the negation of the respective operator==().
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.