Logo Search packages:      
Sourcecode: pwlib version File versions

PString Class Reference

#include <pstring.h>

Inheritance diagram for PString:

PCaselessString PDirectory PFilePath PStringStream PColourConverterRegistration PHTML PSynonymColourRegistration

List of all members.

Detailed Description

The character string class. It supports a wealth of additional functions for string processing and conversion. Operators are provided so that strings can virtually be treated as a basic type.

An important feature of the string class, which is not present in other container classes, is that when the string contents is changed, that is resized or elements set, the string is "dereferenced", and a duplicate made of its contents. That is this instance of the array is disconnected from all other references to the string data, if any, and a new string array contents created. For example consider the following: {verbatim} PString s1 = "String"; // New array allocated and set to "String" PString s2 = s1; // s2 has pointer to same array as s1 and reference count is 2 for both s1[0] = 's'; // Breaks references into different strings {verbatim} at the end s1 is "string" and s2 is "String" both with reference count of 1.

The functions that will "break" a reference are SetSize()#, SetMinSize()#, GetPointer()#, SetAt()# and operator[]#.

Note that the array is a '' terminated string as in C strings. Thus the memory allocated, and the length of the string may be different values.

Also note that the PString is inherently an 8 bit string. The character set is not defined for most operations and it may be any 8 bit character set. However when conversions are being made to or from 2 byte formats then the PString is assumed to be the UTF-8 format. The 2 byte format is nominally UCS-2 (aka BMP string) and while it is not exactly the same as UNICODE they are compatible enough for them to be treated the same for most real world usage.

Definition at line 376 of file pstring.h.


enum  ConversionType {
  Pascal, Basic, Literal, Signed,
  Unsigned, Decimal, Exponent, Printf,
virtual PStringMakeEmpty ()
PStringoperator= (PUInt64 n)
PStringoperator= (PInt64 n)
PStringoperator= (unsigned long n)
PStringoperator= (long n)
PStringoperator= (unsigned int n)
PStringoperator= (int n)
PStringoperator= (unsigned short n)
PStringoperator= (short n)
PStringoperator= (char ch)
PStringoperator= (const char *cstr)
PStringoperator= (const PString &str)
 PString (ConversionType type, double value, unsigned places)
 PString (ConversionType type, long value, unsigned base=10)
 PString (ConversionType type, const char *str,...)
 PString (PUInt64 n)
 PString (PInt64 n)
 PString (unsigned long n)
 PString (long n)
 PString (unsigned int n)
 PString (int n)
 PString (unsigned short n)
 PString (short n)
 PString (char ch)
 PString (const PWORDArray &ustr)
 PString (const WORD *ustr, PINDEX len)
 PString (const char *cstr, PINDEX len)
 PString (const WORD *ustr)
 PString (const char *cstr)
PINLINE PString (const std::string &str)
PINLINE PString (const PString &str)
PINLINE PString ()
static PString Empty ()

Conversion functions

PInt64 AsInt64 (unsigned base=10) const
long AsInteger (unsigned base=10) const
double AsReal () const
PWORDArray AsUCS2 () const
DWORD AsUnsigned (unsigned base=10) const
PUInt64 AsUnsigned64 (unsigned base=10) const
 operator const unsigned char * () const
PStringsprintf (const char *cfmt,...)
PString ToLiteral () const
PBYTEArray ToPascal () const
PStringvsprintf (const char *cfmt, va_list args)
PStringvsprintf (const PString &fmt, va_list args)
PString psprintf (const char *cfmt,...)
PString pvsprintf (const PString &fmt, va_list args)
PString pvsprintf (const char *cfmt, va_list args)

Concatenation operators

PString operator & (char ch) const
PString operator & (const char *cstr) const
PString operator & (const PString &str) const
PStringoperator &= (char ch)
PStringoperator &= (const char *cstr)
PStringoperator &= (const PString &str)
PString operator+ (char ch) const
PString operator+ (const char *cstr) const
PString operator+ (const PString &str) const
PStringoperator+= (char ch)
PStringoperator+= (const char *cstr)
PStringoperator+= (const PString &str)
PString operator & (char ch, const PString &str)
PString operator & (const char *cstr, const PString &str)
PString operator+ (char c, const PString &str)
PString operator+ (const char *cstr, const PString &str)

Public Member Functions

Overrides from class PObject
virtual PObjectClone () const
virtual Comparison Compare (const PObject &obj) const
virtual PINDEX HashFunction () const
virtual void PrintOn (ostream &strm) const
virtual void ReadFrom (istream &strm)
Search & replace functions
void Delete (PINDEX start, PINDEX len)
PINDEX Find (const char *cstr, PINDEX offset=0) const
PINDEX Find (const PString &str, PINDEX offset=0) const
PINDEX Find (char ch, PINDEX offset=0) const
PINDEX FindLast (const char *cstr, PINDEX offset=P_MAX_INDEX) const
PINDEX FindLast (const PString &str, PINDEX offset=P_MAX_INDEX) const
PINDEX FindLast (char ch, PINDEX offset=P_MAX_INDEX) const
PINDEX FindOneOf (const char *cset, PINDEX offset=0) const
PINDEX FindOneOf (const PString &set, PINDEX offset=0) const
BOOL FindRegEx (const PRegularExpression &regex, PINDEX &pos, PINDEX &len, PINDEX offset=0, PINDEX maxPos=P_MAX_INDEX) const
PINDEX FindRegEx (const PRegularExpression &regex, PINDEX offset=0) const
void Replace (const PString &target, const PString &subs, BOOL all=FALSE, PINDEX offset=0)
void Splice (const char *cstr, PINDEX pos, PINDEX len=0)
void Splice (const PString &str, PINDEX pos, PINDEX len=0)
Size/Length functions
PINLINE PINDEX GetLength () const
BOOL MakeMinimumSize ()
bool operator! () const
Overrides from class PContainer
virtual BOOL IsEmpty () const
virtual BOOL MakeUnique ()
virtual BOOL SetSize (PINDEX newSize)
Sub-string functions
PString Left (PINDEX len) const
PString LeftTrim () const
PStringArray Lines () const
PString Mid (PINDEX start, PINDEX len=P_MAX_INDEX) const
PString operator() (PINDEX start, PINDEX end) const
PString Right (PINDEX len) const
PString RightTrim () const
PStringArray Tokenise (const char *cseparators, BOOL onePerSeparator=TRUE) const
PStringArray Tokenise (const PString &separators, BOOL onePerSeparator=TRUE) const
PString ToLower () const
PString ToUpper () const
PString Trim () const
Comparison operators
Comparison NumCompare (const char *cstr, PINDEX count=P_MAX_INDEX, PINDEX offset=0) const
Comparison NumCompare (const PString &str, PINDEX count=P_MAX_INDEX, PINDEX offset=0) const
bool operator!= (const char *cstr) const
bool operator!= (const PObject &str) const
bool operator*= (const char *cstr) const
bool operator*= (const PString &str) const
bool operator< (const char *cstr) const
bool operator< (const PObject &str) const
bool operator<= (const char *cstr) const
bool operator<= (const PObject &str) const
bool operator== (const char *cstr) const
bool operator== (const PObject &str) const
bool operator> (const char *cstr) const
bool operator> (const PObject &str) const
bool operator>= (const char *cstr) const
bool operator>= (const PObject &str) const

Protected Member Functions

virtual Comparison InternalCompare (PINDEX offset, PINDEX length, const char *cstr) const
virtual Comparison InternalCompare (PINDEX offset, char c) const
void InternalFromUCS2 (const WORD *ptr, PINDEX len)
 PString (int dummy, const PString *str)

Private Member Functions

 PCLASSINFO (PString, PCharArray)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index