Unicorn XML Toolkit
Version 1.50.00

Namespace Core
Class CString

class CString {
public:
    CString();
    CString(const CString& strSrc);
    CString(WCHAR ch, int nRepeat=1);
    CString(const WCHAR *pch, int nLength);
    CString(const WCHAR *psz);
    CString(char *psz);
    CString(const wstring &wstr);
    ~CString();
public:
    int GetLength() const;
    bool IsEmpty() const;
    void Empty();
    WCHAR GetAt(int nIndex) const;
    WCHAR operator [](int nIndex) const;
    void SetAt(int nIndex, WCHAR ch);
    operator PCWSTR() const;
    const CString& operator=(const CString& strSrc);
    const CString& operator=(const WCHAR ch);
    const CString& operator=(const WCHAR *psz);
    const CString& operator=(char *psz);
    friend CString operator+(
            const CString &str1, const CString &str2);
    friend CString operator+(const CString &str, WCHAR ch);
    friend CString operator+(WCHAR ch, const CString &str);
    friend CString operator+(const CString &str, const WCHAR *psz);
    friend CString operator+(const WCHAR *psz, const CString &str);
    const CString &operator+=(const CString &str);
    const CString &operator+=(WCHAR ch);
    const CString &operator+=(const WCHAR *psz);
    friend bool operator==(const CString &str1, const CString &str2);
    friend bool operator==(const CString &str1, const WCHAR *psz2);
    friend bool operator==(const WCHAR *psz1, const CString &str2);
    friend bool operator!=(const CString &str1, const CString &str2);
    friend bool operator!=(const CString &str1, const WCHAR *psz2);
    friend bool operator!=(const WCHAR *psz1, const CString &str2);
    friend bool operator<(const CString &str1, const CString &str2);
    friend bool operator<(const CString &str1, const WCHAR *psz2);
    friend bool operator<(const WCHAR *psz1, const CString &str2);
    friend bool operator>(const CString &str1, const CString &str2);
    friend bool operator>(const CString &str1, const WCHAR *psz2);
    friend bool operator>(const WCHAR *psz1, const CString &str2);
    friend bool operator<=(const CString &str1, const CString &str2);
    friend bool operator<=(const CString &str1, const WCHAR *psz2);
    friend bool operator<=(const WCHAR *psz1, const CString &str2);
    friend bool operator>=(const CString &str1, const CString &str2);
    friend bool operator>=(const CString &str1, const WCHAR *psz2);
    friend bool operator>=(const WCHAR *psz1, const CString &str2);
    int Compare(const WCHAR *psz) const;
    int CompareNoCase(const WCHAR *psz) const;
    CString Mid(int nFirst) const;
    CString Mid(int nFirst, int nCount) const;
    CString Left(int nCount) const;
    CString Right(int nCount) const;
    void MakeUpper();
    void MakeLower();
    void MakeReverse();
    void TrimLeft();
    void TrimRight();
    int Find(WCHAR ch) const;
    int Find(const WCHAR *pszSub) const;
    };

The string of 16-bit characters.

This class is built on the top of the class wstring from the C++ Standard Template Library (STL).

Since:
1.00.00
Version:
1.50.00
Author:
Alexey Gokhberg
Constructor/Destructor Summary
CString ();
����������Constructs the empty string
CString (const CString& strSrc);
����������Constructs the string copying another string.
CString (WCHAR ch, int nRepeat=1);
����������Constructs the string containing the specified character in all positions.
CString (const WCHAR *pch, int nLength);
����������Constructs the string from the array of 16-bit characters.
CString (const WCHAR *psz);
����������Constructs the string from the null-terminated array of 16-bit characters.
CString (char *psz);
����������Constructs the string from the null-terminated array of 8-bit characters.
CString (const wstring &wstr);
����������Constructs the string from the STL wide string.
~CString ();
����������Destroys the string.

Function Summary
int GetLength () const;
����������Returns the length of this string.
bool IsEmpty () const;
����������Tests whether this string is empty (contains no characters).
void Empty ();
����������Removes all characters from this string.
WCHAR GetAt (int nIndex) const;
����������Returns the character at the specified index in this string.
WCHAR operator [] (int nIndex) const;
����������Returns the character at the specified index in this string.
void SetAt (int nIndex, WCHAR ch);
����������Sets the specified character at the specified index in this string.
operator PCWSTR () const;
����������Returns the null-terminated array of all characters contained in this string.
const�CString& operator= (const CString& strSrc);
����������Assigns the specified string to this string.
const�CString& operator= (const WCHAR ch);
����������Assigns a string containing the specified single character to this string.
const�CString& operator= (const WCHAR *psz);
����������Assigns the null-terminated array of 16-bit characters to this string.
const�CString& operator= (char *psz);
����������Assigns the null-terminated array of 8-bit characters to this string.
CString operator+ (const CString &str1, const CString &str2);
����������Concatenates two strings.
CString operator+ (const CString &str, WCHAR ch);
����������Concatenates a string and a character.
CString operator+ (WCHAR ch, const CString &str);
����������Concatenates a character and a string.
CString operator+ (const CString &str, const WCHAR *psz);
����������Concatenates a string and a null-terminated array of characters.
CString operator+ (const WCHAR *psz, const CString &str);
����������Concatenates a null-terminated array of characters and a string.
const�CString�& operator+= (const CString &str);
����������Appends the specified string to the end of this string.
const�CString�& operator+= (WCHAR ch);
����������Appends the specified character to the end of this string.
const�CString�& operator+= (const WCHAR *psz);
����������Appends the specified null-terminated array of characters to the end of this string.
bool operator== (const CString &str1, const CString &str2);
����������Performs the equality comparison operation on two strings.
bool operator== (const CString &str1, const WCHAR *psz2);
����������Performs the equality comparison operation on a string and a null-terminated array of characters.
bool operator== (const WCHAR *psz1, const CString &str2);
����������Performs the equality comparison operation on a null-terminated array of characters and a string.
bool operator!= (const CString &str1, const CString &str2);
����������Performs the non-equality comparison operation on two strings.
bool operator!= (const CString &str1, const WCHAR *psz2);
����������Performs the non-equality comparison operation on a string and a null-terminated array of characters.
bool operator!= (const WCHAR *psz1, const CString &str2);
����������Performs the non-equality comparison operation on a null-terminated array of characters and a string.
bool operator< (const CString &str1, const CString &str2);
����������Performs the less-than comparison operation on two strings.
bool operator< (const CString &str1, const WCHAR *psz2);
����������Performs the less-than comparison operation on a string and a null-terminated array of characters.
bool operator< (const WCHAR *psz1, const CString &str2);
����������Performs the less-than comparison operation on a null-terminated array of characters and a string.
bool operator> (const CString &str1, const CString &str2);
����������Performs the greater-than comparison operation on two strings.
bool operator> (const CString &str1, const WCHAR *psz2);
����������Performs the greater-than comparison operation on a string and a null-terminated array of characters.
bool operator> (const WCHAR *psz1, const CString &str2);
����������Performs the greater-than comparison operation on a null-terminated array of characters and a string.
bool operator<= (const CString &str1, const CString &str2);
����������Performs the less-than-or-equal comparison operation on two strings.
bool operator<= (const CString &str1, const WCHAR *psz2);
����������Performs the less-than-or-equal comparison operation on a string and a null-terminated array of characters.
bool operator<= (const WCHAR *psz1, const CString &str2);
����������Performs the less-than-or-equal comparison operation on a null-terminated array of characters and a string.
bool operator>= (const CString &str1, const CString &str2);
����������Performs the greater-than-or-equal comparison operation on two strings.
bool operator>= (const CString &str1, const WCHAR *psz2);
����������Performs the greater-than-or-equal comparison operation on a string and a null-terminated array of characters.
bool operator>= (const WCHAR *psz1, const CString &str2);
����������Performs the greater-than-or-equal comparison operation on a null-terminated array of characters and a string.
int Compare (const WCHAR *psz) const;
����������Compares this string with the null-terminated array of charcters.
int CompareNoCase (const WCHAR *psz) const;
����������Compares, ignoring case, this string with the null-terminated array of charcters.
CString Mid (int nFirst) const;
����������Extracts the trailing part of this string.
CString Mid (int nFirst, int nCount) const;
����������Extracts the middle part of this string.
CString Left (int nCount) const;
����������Extracts the left part of this string.
CString Right (int nCount) const;
����������Extracts the right part of this string.
void MakeUpper ();
����������Converts content of this string to an upper case.
void MakeLower ();
����������Converts content of this string to a lower case.
void MakeReverse ();
����������Places content of this string in a reverse order.
void TrimLeft ();
����������Removes leading whitespaces in the content of this string.
void TrimRight ();
����������Removes trailing whitespaces in the content of this string.
int Find (WCHAR ch) const;
����������Searches for the first occurence of the specified character in this string.
int Find (const WCHAR *pszSub) const;
����������Searches for the first occurence of the specified null-terminated character array in this string.

Constructor/Destructor Detail

CString

CString();

Constructs the empty string

CString

CString(const CString& strSrc);

Constructs the string copying another string.

Parameters:
strSrc - the string to copy

CString

CString(WCHAR ch, int nRepeat=1);

Constructs the string containing the specified character in all positions.

Parameters:
ch - the character
nRepeat - the repeat counter

CString

CString(const WCHAR *pch, int nLength);

Constructs the string from the array of 16-bit characters.

Parameters:
pch - the array of characters
nLength - the number of characters in the array

CString

CString(const WCHAR *psz);

Constructs the string from the null-terminated array of 16-bit characters.

Parameters:
psz - the array of characters (null-terminated)

CString

CString(char *psz);

Constructs the string from the null-terminated array of 8-bit characters.

Parameters:
psz - the array of characters (null-terminated)

CString

CString(const wstring &wstr);

Constructs the string from the STL wide string.

Parameters:
wstr - the STL wide string

~CString

~CString();

Destroys the string.

Function Detail

GetLength

int GetLength() const;

Returns the length of this string.

Returns:
the length of this string

IsEmpty

bool IsEmpty() const;

Tests whether this string is empty (contains no characters).

Returns:
true if this string is empty; false otherwise

Empty

void Empty();

Removes all characters from this string.

GetAt

WCHAR GetAt(int nIndex) const;

Returns the character at the specified index in this string.

The result is unspecified in the index is out of range.

Parameters:
nIndex - the index (zero-based)
Returns:
the character at the specified index in this string

operator []

WCHAR operator [](int nIndex) const;

Returns the character at the specified index in this string.

The result is unspecified in the index is out of range.

Parameters:
nIndex - the index (zero-based)
Returns:
the character at the specified index in this string

SetAt

void SetAt(int nIndex, WCHAR ch);

Sets the specified character at the specified index in this string.

Parameters:
nIndex - the index (zero-based)
ch - the character

PCWSTR

operator PCWSTR() const;

Returns the null-terminated array of all characters contained in this string.

This array may become invalid after any update operation performed on this string.

Returns:
the null-terminated array of all characters contained in this string

operator=

const CString& operator=(const CString& strSrc);

Assigns the specified string to this string.

Parameters:
strSrc - the string to assign
Returns:
this string

operator=

const CString& operator=(const WCHAR ch);

Assigns a string containing the specified single character to this string.

Parameters:
ch - the character to assign
Returns:
this string

operator=

const CString& operator=(const WCHAR *psz);

Assigns the null-terminated array of 16-bit characters to this string.

Parameters:
psz - the null-terminated array of characters to assign
Returns:
this string

operator=

const CString& operator=(char *psz);

Assigns the null-terminated array of 8-bit characters to this string.

Parameters:
psz - the null-terminated array of characters to assign
Returns:
this string

operator+

friend CString operator+(
        const CString &str1, const CString &str2);

Concatenates two strings.

Parameters:
str1 - the first string
str2 - the second string
Returns:
the result of concatenation

operator+

friend CString operator+(const CString &str, WCHAR ch);

Concatenates a string and a character.

Parameters:
str - the string
ch - the character
Returns:
the result of concatenation

operator+

friend CString operator+(WCHAR ch, const CString &str);

Concatenates a character and a string.

Parameters:
ch - the character
str - the string
Returns:
the result of concatenation

operator+

friend CString operator+(const CString &str, const WCHAR *psz);

Concatenates a string and a null-terminated array of characters.

Parameters:
str - the string
psz - the null-terminated array of characters
Returns:
the result of concatenation

operator+

friend CString operator+(const WCHAR *psz, const CString &str);

Concatenates a null-terminated array of characters and a string.

Parameters:
psz - the null-terminated array of characters
str - the string
Returns:
the result of concatenation

operator+=

const CString &operator+=(const CString &str);

Appends the specified string to the end of this string.

Parameters:
str - the string to append
Returns:
this string

operator+=

const CString &operator+=(WCHAR ch);

Appends the specified character to the end of this string.

Parameters:
ch - the character to append
Returns:
this string

operator+=

const CString &operator+=(const WCHAR *psz);

Appends the specified null-terminated array of characters to the end of this string.

Parameters:
psz - the null-terminated array of characters to append
Returns:
this string

operator==

friend bool operator==(const CString &str1, const CString &str2);

Performs the equality comparison operation on two strings.

Parameters:
str1 - the first string
str2 - the second string
Returns:
the result of comparison

operator==

friend bool operator==(const CString &str1, const WCHAR *psz2);

Performs the equality comparison operation on a string and a null-terminated array of characters.

Parameters:
str1 - the string
psz2 - the null-terminated array of characters
Returns:
the result of comparison

operator==

friend bool operator==(const WCHAR *psz1, const CString &str2);

Performs the equality comparison operation on a null-terminated array of characters and a string.

Parameters:
psz1 - the null-terminated array of characters
str2 - the string
Returns:
the result of comparison

operator!=

friend bool operator!=(const CString &str1, const CString &str2);

Performs the non-equality comparison operation on two strings.

Parameters:
str1 - the first string
str2 - the second string
Returns:
the result of comparison

operator!=

friend bool operator!=(const CString &str1, const WCHAR *psz2);

Performs the non-equality comparison operation on a string and a null-terminated array of characters.

Parameters:
str1 - the string
psz2 - the null-terminated array of characters
Returns:
the result of comparison

operator!=

friend bool operator!=(const WCHAR *psz1, const CString &str2);

Performs the non-equality comparison operation on a null-terminated array of characters and a string.

Parameters:
psz1 - the null-terminated array of characters
str2 - the string
Returns:
the result of comparison

operator<

friend bool operator<(const CString &str1, const CString &str2);

Performs the less-than comparison operation on two strings.

Parameters:
str1 - the first string
str2 - the second string
Returns:
the result of comparison

operator<

friend bool operator<(const CString &str1, const WCHAR *psz2);

Performs the less-than comparison operation on a string and a null-terminated array of characters.

Parameters:
str1 - the string
psz2 - the null-terminated array of characters
Returns:
the result of comparison

operator<

friend bool operator<(const WCHAR *psz1, const CString &str2);

Performs the less-than comparison operation on a null-terminated array of characters and a string.

Parameters:
psz1 - the null-terminated array of characters
str2 - the string
Returns:
the result of comparison

operator>

friend bool operator>(const CString &str1, const CString &str2);

Performs the greater-than comparison operation on two strings.

Parameters:
str1 - the first string
str2 - the second string
Returns:
the result of comparison

operator>

friend bool operator>(const CString &str1, const WCHAR *psz2);

Performs the greater-than comparison operation on a string and a null-terminated array of characters.

Parameters:
str1 - the string
psz2 - the null-terminated array of characters
Returns:
the result of comparison

operator>

friend bool operator>(const WCHAR *psz1, const CString &str2);

Performs the greater-than comparison operation on a null-terminated array of characters and a string.

Parameters:
psz1 - the null-terminated array of characters
str2 - the string
Returns:
the result of comparison

operator<=

friend bool operator<=(const CString &str1, const CString &str2);

Performs the less-than-or-equal comparison operation on two strings.

Parameters:
str1 - the first string
str2 - the second string
Returns:
the result of comparison

operator<=

friend bool operator<=(const CString &str1, const WCHAR *psz2);

Performs the less-than-or-equal comparison operation on a string and a null-terminated array of characters.

Parameters:
str1 - the string
psz2 - the null-terminated array of characters
Returns:
the result of comparison

operator<=

friend bool operator<=(const WCHAR *psz1, const CString &str2);

Performs the less-than-or-equal comparison operation on a null-terminated array of characters and a string.

Parameters:
psz1 - the null-terminated array of characters
str2 - the string
Returns:
the result of comparison

operator>=

friend bool operator>=(const CString &str1, const CString &str2);

Performs the greater-than-or-equal comparison operation on two strings.

Parameters:
str1 - the first string
str2 - the second string
Returns:
the result of comparison

operator>=

friend bool operator>=(const CString &str1, const WCHAR *psz2);

Performs the greater-than-or-equal comparison operation on a string and a null-terminated array of characters.

Parameters:
str1 - the string
psz2 - the null-terminated array of characters
Returns:
the result of comparison

operator>=

friend bool operator>=(const WCHAR *psz1, const CString &str2);

Performs the greater-than-or-equal comparison operation on a null-terminated array of characters and a string.

Parameters:
psz1 - the null-terminated array of characters
str2 - the string
Returns:
the result of comparison

Compare

int Compare(const WCHAR *psz) const;

Compares this string with the null-terminated array of charcters.

This function returns a negative integer if this string is less than the string represented by the specified array, a positive integer if this string is greater than the string represented by the specified array, and zero if this string and the string represented by the specified array are equal.

Parameters:
psz - the null-terminated array of characters
Returns:
the result of comparison

CompareNoCase

int CompareNoCase(const WCHAR *psz) const;

Compares, ignoring case, this string with the null-terminated array of charcters.

This function returns a negative integer if this string is less than the string represented by the specified array, a positive integer if this string is greater than the string represented by the specified array, and zero if this string and the string represented by the specified array are equal.

Parameters:
psz - the null-terminated array of characters
Returns:
the result of comparison

Mid

CString Mid(int nFirst) const;

Extracts the trailing part of this string.

Parameters:
nFirst - the index (zero-based) of the first character of the part to extract
Returns:
the new string containing the extracted part

Mid

CString Mid(int nFirst, int nCount) const;

Extracts the middle part of this string.

Parameters:
nFirst - the index (zero-based) of the first character of the part to extract
nCount - the number of characters to extract
Returns:
the new string containing the extracted part

Left

CString Left(int nCount) const;

Extracts the left part of this string.

Parameters:
nCount - the number of characters to extract
Returns:
the new string containing the extracted part

Right

CString Right(int nCount) const;

Extracts the right part of this string.

Parameters:
nCount - the number of characters to extract
Returns:
the new string containing the extracted part

MakeUpper

void MakeUpper();

Converts content of this string to an upper case.

MakeLower

void MakeLower();

Converts content of this string to a lower case.

MakeReverse

void MakeReverse();

Places content of this string in a reverse order.

TrimLeft

void TrimLeft();

Removes leading whitespaces in the content of this string.

TrimRight

void TrimRight();

Removes trailing whitespaces in the content of this string.

Find

int Find(WCHAR ch) const;

Searches for the first occurence of the specified character in this string.

Parameters:
ch - the character to search
Returns:
the index of the first occurence of the specified character in this string, or -1 if none was found

Find

int Find(const WCHAR *pszSub) const;

Searches for the first occurence of the specified null-terminated character array in this string.

Parameters:
pszSub - the null-terminated character array to search
Returns:
the index of the first occurence of the specified character array in this string, or -1 if none was found

Unicorn XML Toolkit
Version 1.50.00


This document was created using Unicorn DOC++.

Copyright 1999-2001 Unicorn Enterprises SA.
All Rights Reserved.