Xavax C++ Library Class Index   FAQ   Overview

Class xavax::String

String is a string class that automatically manages memory usage. If a string needs to expand to append or insert new data, storage is automatically reallocated. Since the underlying string values may be shared, any method which modifies an object may force the buffer to be reallocated which may result in a OutOfMemoryException.

Constructor Summary
String()
         Construct an empty string.
String(size_t size)
         Construct an empty string with an initial capacity of size.
String(const String& src)
         Construct a new string that is a copy of src.
String(const char* s)
         Construct a new string with the initial value taken from the null-terminated character string s.
String(const char* s, size_t n)
         Construct an new string with an initial capacity of n and the initial value taken from the first n characters of s.

Operator Summary
String& operator=(const String& src)
         Copy the value of src to this object.
String& operator=(const char* s)
         Copy the string s to this object.
String& operator+=(const String& src)
         Append the value of src to this object.
String& operator+=(const char* s)
         Append the string s to this object.
String& operator+=(char c)
         Append the character c to this object.
const char* operator()()
         Return the value of this object.
bool operator==(const String& rhs)
         Return true if the value of this object and the value of rhs are equal.
bool operator==(const char* rhs)
         Return true if the value of this object and the string rhs are equal.
bool operator!=(const String& rhs)
         Return true if the value of this object and the value of rhs are not equal.
bool operator!=(const char* rhs)
         Return true if the value of this object and the string rhs are not equal.
bool operator<=(const String& rhs)
         Return true if the value of this object is less than or equal to the value of rhs.
bool operator<=(const char* rhs)
         Return true if the value of this object is less than or equal to the string rhs.
bool operator>=(const String& rhs)
         Return true if the value of this object is greater than or equal to the value of rhs.
bool operator>=(const char* rhs)
         Return true if the value of this object is greater than or equal to the string rhs.
bool operator<(const String& rhs)
         Return true if the value of this object is less than the value of rhs.
bool operator<(const char* rhs)
         Return true if the value of this object is less than the string rhs.
bool operator>(const String& rhs)
         Return true if the value of this object is greater than the value of rhs.
bool operator>(const char* rhs)
         Return true if the value of this object is greater than the string rhs.

Method Summary
void append(char c)
         Append character c to the value of this object.
void append(const char* s)
         Append string s to the value of this object.
void append(const char* s, size_t n)
         Append the first n characters of string s to the value of this object.
void append(const String& s)
         Append the value of s to the value of this object.
void append(const String& s, size_t n)
         Append the first n characters of the value of object s to the value of this string.
void insert(char c, size_t p)
         Insert character c into the value of this object at position p.
void insert(const char* s, size_t p)
         Insert string s into the value of this object at position p.
void insert(const char* s, size_t n, size_t p)
         Insert the first n characters of string s into the value of this object at position p.
void insert(const String& s, size_t p)
         Insert the value of s into the value of this object at position p.
void insert(const String& s, size_t n, size_t p)
         Insert the first n characters of the value of object s into the value of this string at position p.
size_t length()
         Return the length of the string value.
void replace(char c, size_t p1, size_t p2)
         Replace a substring with the character c.
void replace(const char* s, size_t p)
         Replace a substring with string s.
void replace(const char* s, size_t n, size_t p)
         Replace a substring with the first n characters of string s.
void replace(const String& s, size_t p)
         Replace a substring with the value of object s.
void replace(const String& s, size_t n, size_t p)
         Replace a substring with the first n characters of the value of object s.
void remove()
         Remove a substring from the string.
void truncate()
         Truncate the string to the specified length.

Methods Inherited From Object
cast<T>, cast<T>, classRecord, ClassRecord, clone, hashCode

Related Classes
RCObject, RCPointer.

Constructor Detail

String

String()
Construct an empty string.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

String

String(size_t size)
Construct an empty string with an initial capacity of size.
Parameters:
size - the initial capacity.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

String

String(const String& src)
Construct a new string that is a copy of src.
Parameters:
src - the string to be copied.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

String

String(const char* s)
Construct a new string with the initial value taken from the null-terminated character string s. If s is not null, the initial capacity is the length of s plus 1.
Parameters:
s - the initial string value.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

String

String(const char* s, size_t size)
Construct an new string with an initial capacity of n and the initial value taken from the first n characters of s.
Parameters:
s - the initial string value.
size - the initial capacity.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

Operator Detail

operator=

String& operator=(String& src)
Copy the value of src to this object.
Parameters:
src - the string to be copied.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

operator=

String& operator=(const char* s)
Copy string s to this object.
Parameters:
s - the string to be copied.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

operator+=

String& operator+=(String& src)
Append the value of src to this object.
Parameters:
src - the string to be appended.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

operator+=

String& operator+=(const char* s)
Append the string s to this object.
Parameters:
s - the string to be appended.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

operator+=

String& operator+=(char c)
Append the character c to this object.
Parameters:
c - the character to be appended.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

operator()

String& operator()()
Return the value of this object as a character string.
Returns:
the value of this object.

operator==

bool operator==(const String& rhs)
Returns true if the value of this object is equal to the value of rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is equal to the value of rhs.

operator==

bool operator==(const char* rhs)
Returns true if the value of this object is equal to the string rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is equal to the string rhs.

operator!=

bool operator!=(const String& rhs)
Returns true if the value of this object is not equal to the value of rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is not equal to the value of rhs.

operator!=

bool operator!=(const char* rhs)
Returns true if the value of this object is not equal to the string rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is not equal to the string rhs.

operator<=

bool operator<=(const String& rhs)
Returns true if the value of this object is less than or equal to the value of rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is less than or equal to the value of rhs.

operator<=

bool operator<=(const char* rhs)
Returns true if the value of this object is less than or equal to the string rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is less than or equal to the string rhs.

operator>=

bool operator>=(const String& rhs)
Returns true if the value of this object is greater than or equal to the value of rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is greater than or equal to the value of rhs.

operator>=

bool operator>=(const char* rhs)
Returns true if the value of this object is greater than or equal to the string rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is greater than or equal to the string rhs.

operator<

bool operator<(const String& rhs)
Returns true if the value of this object is less than the value of rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is less than the value of rhs.

operator<

bool operator<(const char* rhs)
Returns true if the value of this object is less than the string rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is less than the string rhs.

operator>

bool operator>(const String& rhs)
Returns true if the value of this object is greater than the value of rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is greater than the value of rhs.

operator>

bool operator>(const char* rhs)
Returns true if the value of this object is greater than the string rhs.
Parameters:
rhs - the right operand of the comparison.
Returns:
if the value of this object is greater than the string rhs.

Method Detail

append

void append(char c)
Append the character c to the value of this object.
Parameters:
c - the character to be appended.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

append

void append(const char* s)
Append the string s to the value of this object.
Parameters:
s - the string to be appended.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

append

void append(const char* s, size_t n)
Append the first n characters of the string s to the value of this object.
Parameters:
s - the string to be appended.
n - the number of characters to be appended.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

append

void append(const String& s)
Append the value of s to the value of this object.
Parameters:
s - the string to be appended.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

append

void append(const String& s, size_t n)
Append the first n characters of the value of s to the value of this object.
Parameters:
s - the string to be appended.
n - the number of characters to be appended.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

insert

void insert(char c, size_t p)
Insert the character c into the value of this object at position p.
Parameters:
c - the character to be inserted.
p - the insertion offset.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

insert

void insert(const char* s, size_t p)
Insert the string s into the value of this object at position p.
Parameters:
s - the string to be inserted.
p - the insertion offset.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

insert

void insert(const char* s, size_t n, size_t p)
Insert the first n characters of the string s into the value of this object at position p.
Parameters:
s - the string to be inserted.
n - the number of characters to be inserted.
p - the insertion offset.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

insert

void insert(const String& s, size_t p)
Insert the value of s into the value of this object at position p.
Parameters:
s - the string to be inserted.
p - the insertion offset.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

insert

void insert(const String& s, size_t n, size_t p)
Insert the first n characters of the value of s into the value of this object at position p.
Parameters:
s - the string to be inserted.
n - the number of characters to be inserted.
p - the insertion offset.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

length

size_t length()
Return the length of this string.
Returns:
the length of this string.

replace

void replace(char c, size_t p1, size_t p2)
Replace a substring starting at position p1 and ending at position p2 with the character c.
Parameters:
c - the character to be inserted.
p1 - the starting position of the substring.
p2 - the ending position of the substring.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

replace

void replace(const char* s, size_t p1, size_t p2)
Replace a substring starting at position p1 and ending at position p2 with the string s.
Parameters:
s - the string to be inserted.
p1 - the starting position of the substring.
p2 - the ending position of the substring.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

replace

void replace(const char* s, size_t n, size_t p1, size_t p2)
Replace a substring starting at position p1 and ending at position p2 with the first n characters of the string s.
Parameters:
s - the string to be inserted.
n - the number of characters to be inserted.
p1 - the starting position of the substring.
p2 - the ending position of the substring.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

replace

void replace(const String& s, size_t p1, size_t p2)
Replace a substring starting at position p1 and ending at position p2 with the value of s.
Parameters:
s - the string to be inserted.
p1 - the starting position of the substring.
p2 - the ending position of the substring.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

replace

void replace(const String& s, size_t n, size_t p1,
size_t p2)
Replace a substring starting at position p1 and ending at position p2 with the first n characters of the value of s.
Parameters:
s - the string to be inserted.
n - the number of characters to be inserted.
p1 - the starting position of the substring.
p2 - the ending position of the substring.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.
RangeException - if sufficient memory cannot be allocated.

remove

void remove(size_t p1, size_t p2)
Remove a range of characters beginning with position p1 and ending with position p2.
Parameters:
p1 - the beginning position.
p2 - the ending position.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

truncate

void truncate(size_t n)
Truncate the string to the specified length. If the specified length is greater than the current length, the string is not modified.
Parameters:
n - the new length of the string.
Throws:
OutOfMemoryException - if sufficient memory cannot be allocated.

Example Code

Copyright © 2003 Xavax Inc. -- All Rights Reserved