Module: Essential Tools Module Group: String Processing Classes
Does not inherit
#include <rw/wstring.h> RWWString s(L"test string"); s(6,3); // "tri"
The class RWWSubString allows some subsection of an RWWString 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 RWWString::strip() or the overloaded function call operator taking a regular expression as an argument. There are no public constructors -- RWWSubStrings are constructed by various functions of the RWWString 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 -- Member function overloads with std::wstring will only appear when building on top of the C++ Standard Library.
None
#include <iostream> #include <rw/wstring.h> int main() { RWWString s (L"What I tell you is true."); std::cout << "Take the string: [" << s << "]\n"; // Create a substring and use it as an lvalue: s(16, 0) = L"three times "; std::cout << "After assigning text to a substring, it becomes: [" << s << "]" << std::endl; return 0; }
Program output (assuming your platform displays wide characters as ASCII if they are in the ASCII character set):
Take the string: [What I tell you is true.] After assigning text to a substring, it becomes: [What I tell you is three times true.]
RWWSubString& operator=(const RWWString&);
RWWString a; RWWString 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. If self is the null substring, then the statement has no effect. Returns reference to self.
RWWSubString& operator=(const std::wstring& str);
Assignment from an std::wstring. Returns reference to self.
RWWSubString& operator=(const RWWSubString&); RWWSubString& operator=(const RWWConstSubString&);
Assignment from an RWWSubString or an RWWConstSubString, respectively. The statements:
RWWString a; RWWString 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 RWWSubString or RWWConstSubString. If self is the null substring, then the statement has no effect. Returns a reference to self.
RWWSubString& operator=(const wchar_t*);
Assignment from a wide character string. Example:
RWWString wstr(L"Mary had a little lamb"); wchar_t dat[] = L"Perrier"; wstr(11,4) = dat; // "Mary had a Perrier"
Note that the number of characters selected need not match: if they differ, wstr will be resized appropriately. If self is the null substring, then the statement has no effect. Returns reference to self.
wchar_t operator[](size_t i); wchar_t& 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 be thrown.
wchar_t operator()(size_t i); wchar_t& 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/wstring.h>. In that case, if the index is out of range, then an exception of type RWBoundsErr will be thrown.
bool isNull() const;
Returns true if this is a null substring.
size_t length() const;
Returns the extent (length) of the RWWSubString.
bool operator!() const;
Returns true if this is a null substring.
size_t start() const;
Returns the starting element of the RWWSubString.
void toLower();
Changes all upper-case letters in self to lower-case. Uses the C library function towlower().
void toUpper();
Changes all lower-case letters in self to upper-case. Uses the C library function towupper().
bool operator==(const RWWSubString&, const RWWSubString&); bool operator==(const RWWString&, const RWWSubString&); bool operator==(const RWWSubString&, const RWWString& ); bool operator==(const wchar_t*, const RWWSubString&); bool operator==(const RWWSubString&, const wchar_t* );
Returns true if the substring is lexicographically equal to the wide character string or RWWString argument. Case sensitivity is exact.
bool operator!=(const RWWString&, const RWWString& ); bool operator!=(const RWWString&, const RWWSubString&); bool operator!=(const RWWSubString&, const RWWString& ); bool operator!=(const wchar_t*, const RWWString& ); bool operator!=(const RWWString&, const wchar_t* );
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.