SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Related Functions
RWWConstSubString Class Reference

Allows some subsection of an RWWString to be addressed by defining a starting position and an extent. More...

#include <rw/wstring.h>

Public Member Functions

 RWWConstSubString (const RWWSubString &str)
 
 RWWConstSubString (const RWWConstSubString &str)
 
bool isNull () const
 
size_t length () const
 
int operator! () const
 
wchar_t operator() (size_t i) const
 
wchar_t operator[] (short i) const
 
wchar_t operator[] (int i) const
 
wchar_t operator[] (long i) const
 
wchar_t operator[] (unsigned short i) const
 
wchar_t operator[] (unsigned int i) const
 
wchar_t operator[] (unsigned long i) const
 
wchar_t operator[] (long long i) const
 
wchar_t operator[] (unsigned long long i) const
 
size_t start () const
 

Related Functions

(Note that these are not member functions.)

bool operator!= (const RWWConstSubString &lhs, const wchar_t *rhs)
 
bool operator!= (const wchar_t *lhs, const RWWConstSubString &rhs)
 
bool operator!= (const RWWConstSubString &lhs, const RWWConstSubString &rhs)
 
bool operator== (const RWWConstSubString &lhs, const wchar_t *rhs)
 
bool operator== (const wchar_t *lhs, const RWWConstSubString &rhs)
 
bool operator== (const RWWConstSubString &lhs, const RWWConstSubString &rhs)
 

Detailed Description

The class RWWConstSubString 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 on your behalf by such functions as RWWString::strip(). There are no public constructors other than two that allow you to create an RWWConstSubString from an existing RWWSubString or RWWConstSubString. In general, RWWConstSubString objects 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.

Synopsis
#include <rw/wstring.h>
RWWString s("test string");
s(6,3); // "tri"
Persistence
None
Example
#include <iostream>
#include <rw/wstring.h>
int main()
{
const RWWString s (L"What I tell you is true.");
std::cout << "Take the string: [" << s << "]\n";
// Create a string from substrings:
const RWWString s2 (s(0, 16) + L"three times " + s(16, 8));
std::cout << "After creating a string from substrings, you have: ["
<< s2 << "]" << std::endl;
return 0;
}

Program output (assuming your platform displays wide characters as US-ASCII if they are in the US-ASCII character set):

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.]

Constructor & Destructor Documentation

RWWConstSubString::RWWConstSubString ( const RWWSubString str)
inline

Constructs an RWWConstSubString from an existing RWWSubString. The resulting substring references the same start and extent of the RWWString associated with str.

Note
The resulting substring instance should not be used if the RWWString associated with str is modified after the substring is instantiated.
RWWConstSubString::RWWConstSubString ( const RWWConstSubString str)
inline

Copy constructor. The resulting substring references the same start and extent of the RWWString associated with str.

Note
The resulting substring instance should not be used if the RWWString associated with str is modified after the substring is instantiated.

Member Function Documentation

bool RWWConstSubString::isNull ( void  ) const
inline

Returns true if this is a null substring.

size_t RWWConstSubString::length ( ) const
inline

Returns the extent (i.e., length) of the substring.

int RWWConstSubString::operator! ( ) const
inline

Returns true if this is a null substring.

wchar_t RWWConstSubString::operator() ( size_t  i) const
inline

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. Bounds checking is enabled by defining the preprocessor macro RWBOUNDS_CHECK before including <rw/wstring.h>.

Exceptions
RWBoundsErrif RWBOUNDS_CHECK is defined and the index is out of range.
wchar_t RWWConstSubString::operator[] ( short  i) const
inline

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. i is converted to a size_t and bounds checking is performed.

Exceptions
RWBoundsErrif the index is out of range.
wchar_t RWWConstSubString::operator[] ( int  i) const
inline

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. i is converted to a size_t and bounds checking is performed.

Exceptions
RWBoundsErrif the index is out of range.
wchar_t RWWConstSubString::operator[] ( long  i) const
inline

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. i is converted to a size_t and bounds checking is performed.

Exceptions
RWBoundsErrif the index is out of range.
wchar_t RWWConstSubString::operator[] ( unsigned short  i) const
inline

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. i is converted to a size_t and bounds checking is performed.

Exceptions
RWBoundsErrif the index is out of range.
wchar_t RWWConstSubString::operator[] ( unsigned int  i) const
inline

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. i is converted to a size_t and bounds checking is performed.

Exceptions
RWBoundsErrif the index is out of range.
wchar_t RWWConstSubString::operator[] ( unsigned long  i) const
inline

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. i is converted to a size_t and bounds checking is performed.

Exceptions
RWBoundsErrif the index is out of range.
wchar_t RWWConstSubString::operator[] ( long long  i) const

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. i is converted to a size_t and bounds checking is performed.

Exceptions
RWBoundsErrif the index is out of range.
wchar_t RWWConstSubString::operator[] ( unsigned long long  i) const

Returns the i th character of the substring. The index i must be between zero and the length of the substring less one. i is converted to a size_t and bounds checking is performed.

Exceptions
RWBoundsErrif the index is out of range.
size_t RWWConstSubString::start ( void  ) const
inline

Returns the starting element of the substring.

Friends And Related Function Documentation

bool operator!= ( const RWWConstSubString lhs,
const wchar_t *  rhs 
)
related

The equivalent of calling:

!(lhs == rhs)
bool operator!= ( const wchar_t *  lhs,
const RWWConstSubString rhs 
)
related

The equivalent of calling:

!(lhs == rhs)
bool operator!= ( const RWWConstSubString lhs,
const RWWConstSubString rhs 
)
related

The equivalent of calling:

!(lhs == rhs)
bool operator== ( const RWWConstSubString lhs,
const wchar_t *  rhs 
)
related

Returns true if lhs is lexicographically equal to rhs. Otherwise returns false. Use member RWWString::collate() or RWWString::strXForm() for locale-sensitive comparisons.

bool operator== ( const wchar_t *  lhs,
const RWWConstSubString rhs 
)
related

Returns true if lhs is lexicographically equal to rhs. Otherwise returns false. Use member RWWString::collate() or RWWString::strXForm() for locale-sensitive comparisons.

bool operator== ( const RWWConstSubString lhs,
const RWWConstSubString rhs 
)
related

Returns true if lhs is lexicographically equal to rhs. Otherwise returns false. Use member RWWString::collate() or RWWString::strXForm() for locale-sensitive comparisons.

Copyright © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.