#include <CNCL/String.h>
CN_STRING
CNObject
None
CNNamed
CNString
is a dynamic string manipulating class. Each
CNString
manages the string itself (stored as a normal C
character string), the length of the string, and the allocated space.
The characters are indexed from 0 to length-1.
Constructors:
CNString();
CNString(int extra);
CNString(char c);
CNString(char c, int extra);
CNString(const char* cs);
CNString(const char* cs, int extra);
CNString(const CNString& s);
CNString(const CNString& s, int extra);
CNString(CNParam *param);
extra
parameter gives a hint as to
how many extra characters one expects the string to grow. Its default
value is 10.
Destructors:
~CNString();
In addition to the member functions required by CNCL, CNString
provides:
default_extra = 10;
void resize(unsigned i);
void to_lower();
void to_upper();
void capitalize();
void strip_crlf();
void strip_lspace();
void strip_rspace();
void strip_space();
unsigned capacity() const;
unsigned length() const;
CNString after(unsigned pos, unsigned l = 0) const;
CNString before(unsigned pos, unsigned l = 0) const;
CNString& add(char c);
CNString& add(const char* cs);
CNString& del(unsigned pos = 0, unsigned l = 1);
pos
(zero based). Default
values are pos = 0 and l = 1 (e.g. a.del() will delete the first
character of string a). If l is set to 0 all characters beginning at pos
will be deleted (e.g. a.del(0,0) will delete all characters in string
a). Negative pos
values count from end of string.
CNString& del(char c, int pos = 0);
CNString& del(const char* cs, int pos = 0);
CNString& del(const CNString& s, int pos = 0);
CNString& insert(char c, int pos = 0);
CNString& insert(const char* cs, int pos =0);
CNString& insert(const CNString& s, int pos = 0);
CNString& replace(char c, int pos = 0);
CNString& replace(const CNString& s, int pos = 0, int l = 0);
CNString& replace(char oldc, char newc, int pos = 0);
CNString& replace(const CNString& olds, const CNString& news, int pos = 0);
int downsearch(char c, int pos = 0);
int downsearch(const CNString& s, int pos = 0);
int downsearch(const char *cs, int pos = 0);
int upsearch(char c, int pos = 0);
int upsearch(const CNString& s, int pos = 0);
int upsearch(const char *s, int pos=0) const;
bool matches(const char* cs, unsigned pos = 0);
bool matches(const CNString& s, unsigned pos = 0);
operator const char * () const;
CNString
to allow the use of
CNString
s in a char *
context.
char operator ()(int i) const;
char &operator [](int i);
void operator = (const CNString& s);
void operator = (const char* cs);
void operator = (char c);
friend CNString operator + (const CNString& a, const CNString& b);
a
and
b
.
CNString& operator +=(const CNString &s);
CNString& operator +=(const char* cs);
s
or the CNString
cs
to the
end of this string.
friend bool operator < (const CNString& a, const CNString& b);
friend bool operator > (const CNString& a, const CNString& b);
friend bool operator >= (const CNString& a, const CNString& b);
friend bool operator <= (const CNString& a, const CNString& b);
friend bool operator == (const CNString& a, const CNString& b);
friend bool operator != (const CNString& a, const CNString& b);
TRUE
if the relation holds between the strings.
void icopy(istream& strm = cin);
istream &operator >> (istream& strm, CNString& s);
For programming convenience, a type for a const
reference to a
string is provided:
typedef const CNString & CNStringR;
Go to the first, previous, next, last section, table of contents.