AXCEL C++ Framework
Elegance through abstraction
|
String. More...
#include <axcel.h>
Public Member Functions | |
virtual string | type () |
"data" | |
virtual | operator string () |
Convert to string. | |
string () | |
string (const char *s) | |
string (size_t n) | |
string (const string &s) | |
string (const data &s) | |
~string () | |
int | getc () |
Read byte. | |
int | putc (int c) |
Write byte. | |
string & | clear () |
Clear string. | |
bool | empty () |
Is string empty? | |
size_t | len () |
Length. | |
size_t | msize () const |
Resize buffer. | |
string | cat (const char *s, size_t n=0) |
Concatenate string. | |
string | cat (int c, size_t n=1) |
Concatenate character. | |
string | prep (const char *s, size_t n=0) |
Prepend string. | |
string | prep (int c, size_t n=1) |
Prepend character. | |
long | chr (int c, size_t index=0) |
Find first character. | |
long | rchr (int c) |
Find last character. | |
long | str (const char *s, size_t index=0) |
Find first substring. | |
long | rstr (const char *s) |
Find last substring. | |
bool | starts (const char *s) |
Starts with string? | |
bool | starts (int c) |
Starts with character? | |
bool | ends (const char *s) |
Ends with string? | |
bool | ends (int c) |
Ends with character? | |
bool | is (const char *s) |
Same string content? | |
bool | is (int c) |
Same string content? | |
string | cpy (const char *src, size_t index=0, size_t count=0) |
Overwrite string. | |
string | cpy (int c, size_t index=0, size_t count=1) |
Overwrite string. | |
size_t | spn (const char *accept, size_t index=0) |
Length of set. | |
size_t | spn (int c, size_t index=0) |
Length of set. | |
size_t | cspn (const char *reject, size_t index=0) |
Length of set. | |
size_t | cspn (int c, size_t index=0) |
Length of set. | |
string | fry () |
Randomize. | |
long | pbrk (const char *accept, size_t index=0) |
Find any character. | |
long | rpbrk (const char *accept, size_t index=0) |
Reverse find any character. | |
string | substr (size_t start, size_t count) |
Get substring. | |
string | tok (size_t index, const char *delim=" ") |
Extract token. | |
string | tok (size_t index, int delim) |
Extract token. | |
size_t | ntok (const char *delim=" ") |
Count tokens. | |
size_t | ntok (int delim) |
Count tokens. | |
long | itok (size_t index, const char *delim=" ") |
index of token | |
long | itok (size_t index, int delim) |
index of token | |
std::deque< axcel::string > | split (const char *delim=" ") |
Split string. | |
std::deque< axcel::string > | split (int delim) |
Split string. | |
string | wrap (size_t len, const char *eol="\r\n") |
string | left (size_t n) |
Get left substring. | |
string | right (size_t n) |
Get right substring. | |
size_t | nchr (int ch) |
Count of character occurrences. | |
size_t | nstr (const char *str) |
Count of string occurrences. | |
string | rep (const char *oldstr, const char *newstr) |
Search and replace. | |
string | rep (int oldc, int newc) |
Search and replace. | |
string | ins (size_t index, const char *str) |
insert into string | |
string | ins (size_t index, int c) |
insert into string | |
string | rm (size_t index, size_t n) |
Remove characters. | |
string | rev (size_t start=0, size_t count=0) |
Reverse. | |
string | dup (int i) |
Duplicate. | |
string | ror (size_t i=1, size_t index=0, size_t count=0) |
Rotate right. | |
string | rol (size_t i=1, size_t index=0, size_t count=0) |
Rotate left. | |
string | shl (size_t n=1) |
Shift left. | |
string | shr (size_t n=1) |
Shift right. | |
string | lc (size_t start=0, size_t count=0) |
Lowercase. | |
string | uc (size_t start=0, size_t count=0) |
Uppercase. | |
string | q () |
Single-quote string. | |
string | qq () |
Double-quote string. | |
string | qx () |
Execute string. | |
char & | front () |
Get first character. | |
char & | back () |
Get last character. | |
string | esc (const char *format, int(*charfilter)(int)=NULL) |
Escape characters. | |
string | esc (const char *format, const char *chrs) |
Escape characters. | |
string | uesc (const char *format, int(*charfilter)(int)=NULL) |
Unescape string. | |
string | uesc (const char *format, const char *chrs) |
Unescape string. | |
string | untag (int opentag= '<', int closetag= '>') |
Strip tags. | |
string | ltrim () |
Left trim. | |
string | rtrim () |
Right trim. | |
string | strip () |
Strip whitespace. | |
string | chop () |
Remove last character. | |
string | chomp (const char *eat="\r\n") |
Delete ending string. | |
string | chomp (char eat) |
Remove ending character. | |
string | cut () |
Remove first character. | |
string | munch (const char *eat) |
Delete starting string. | |
string | munch (char eat) |
Remove starting character. | |
string | prefix (const char *str) |
Prepend if not existing. | |
string | suffix (const char *str) |
Append if not existing. | |
string | slurp (char c) |
Remove up to first character occurrence. | |
string | rslurp (char c) |
Remove up to last character occurrence. | |
string | burn (char c) |
Remove starting from first character occurrence. | |
string | rburn (char c) |
Remove starting from last character occurrence. | |
string | slurp (const char *s) |
Remove up to first string occurrence. | |
string | rslurp (const char *s) |
Remove up to first string occurrence. | |
string | burn (const char *s) |
Remove starting from last string occurrence. | |
string | rburn (const char *s) |
Remove starting from last string occurrence. | |
string & | swap (string &s) |
Swap string content. | |
string | center (size_t newlen, const char *left, const char *right) |
Center. | |
string | center (size_t newlen, int left, int right) |
Center. | |
string | center (size_t newlen, const char *pad=" ") |
Center. | |
string | center (size_t newlen, int pad) |
Center. | |
string | lpad (size_t newlen, const char *pad=" ") |
Pad left. | |
string | lpad (size_t newlen, int pad) |
Pad left. | |
string | rpad (size_t newlen, const char *pad=" ") |
Pad right. | |
string | rpad (size_t newlen, int pad) |
Pad right. | |
string | squeeze (const char *chrs=0) |
Remove repeating characters. | |
string | squeeze (int chr) |
Remove repeating characters. | |
string | alnums () |
Get alphanumeric characters. | |
string | alphas () |
Get alphabetical characters. | |
string | cntrls () |
Get control characters. | |
string | digits () |
Get digit characters. | |
string | graphs () |
Get printable characters. | |
string | lowers () |
Get lowercase characters. | |
string | prints () |
Get printable characters. | |
string | puncts () |
Get punctuation characters. | |
string | spaces () |
Get whitespace characters. | |
string | uppers () |
Get uppercase characters. | |
string | xdigits () |
Get hex digit characters. | |
string | ctypes (int(*cfunc)(int)) |
Extract characters by type. | |
string | ctypes (const char *chrs) |
Extract specific characters. | |
bool | isalnum () |
Alphanumeric check. | |
bool | isalpha () |
Alphabetical check. | |
bool | iscntrl () |
Control check. | |
bool | isdigit () |
Digit check. | |
bool | isgraph () |
Graph check. | |
bool | islower () |
Lowercase check. | |
bool | isprint () |
Printable check. | |
bool | ispunct () |
Punctuation check. | |
bool | isspace () |
Whitespace check. | |
bool | isupper () |
Uppercase check. | |
bool | isxdigit () |
Hex digit check. | |
bool | isctype (int(*cfunc)(int)) |
Compare character types. | |
bool | isctype (const char *chrs) |
Compare character types. | |
string | inc () |
Alnum increment. | |
string | dec () |
Alnum decrement. | |
string | incn () |
Digit increment. | |
string | decn () |
Digit decrement. | |
string | add (int n) |
Alnum increment recursively. | |
string | add (const char *s) |
string | sub (int n) |
Alnum decrement recursively. | |
string | sub (const char *s) |
string | addn (int n) |
Digit increment recursively. | |
string | addn (const char *s) |
string | subn (int n) |
Digit decrement recursively. | |
string | subn (const char *s) |
unsigned short | cksum () |
Get checksum. | |
int | cmpstr (const char *s,...) |
Compare to multiple strings. | |
int | cmpinstr (const char *s,...) |
Find multiple strings. | |
int | cmpleft (const char *s,...) |
Compare beginning to multiple strings. | |
int | cmpright (const char *s,...) |
Compare end to multiple strings. | |
string & | operator= (string s) |
string & | operator= (const char *s) |
string & | operator= (const data &d) |
string | operator+ (const char *str) |
Concatenate. | |
string | operator+ (char c) |
Concatenate. | |
string & | operator+= (const char *str) |
Concatenate and assign. | |
string & | operator+= (char c) |
Concatenate and assign. | |
string | operator- (const char *str) |
Prepend. | |
string | operator- (char c) |
Prepend. | |
string & | operator-= (const char *str) |
Prepend and assign. | |
string & | operator-= (char c) |
Prepend and assign. | |
bool | operator== (const char *s) |
Is equal? | |
bool | operator== (char c) |
Is equal? | |
bool | operator!= (const char *s) |
Is not equal? | |
bool | operator!= (char c) |
Is not equal? | |
char & | operator[] (int i) |
Reference character. | |
string | operator* (int i) |
Duplicate. | |
string & | operator*= (int i) |
Duplicate and assign. | |
string | operator() () |
Execute string. | |
operator const char * () | |
operator char * () | |
string & | operator++ () |
Digit increment. | |
string | operator++ (int foo) |
Digit increment. | |
string & | operator-- () |
Digit decrement. | |
string | operator-- (int foo) |
Digit decrement. |
String.
Most methods of this string class returns the result by value, not by reference; ergo, methods on a string can be chained together for epic pleasure and efficiency. This class also allows for reading and writing to the string like a file as it inherits from axcel::io::input and axcel::io::output. Unfortunately, this is a string of char's (not a wide character string) and does not support regular expressions.
string axcel::string::add | ( | int | n | ) |
string axcel::string::addn | ( | int | n | ) |
string axcel::string::alnums | ( | ) |
string axcel::string::alphas | ( | ) |
char & axcel::string::back | ( | ) |
string axcel::string::burn | ( | char | c | ) | [inline] |
Remove starting from first character occurrence.
c | Character to find |
Finds the first occurrence of c, and removes that character and all characters proceeding it in this string.
string axcel::string::burn | ( | const char * | s | ) | [inline] |
Remove starting from last string occurrence.
s | string to find |
Finds the first occurrence of s, and removes that string and all characters proceeding it in this string.
string axcel::string::cat | ( | int | c, |
size_t | n = 1 |
||
) |
string axcel::string::cat | ( | const char * | s, |
size_t | n = 0 |
||
) |
string axcel::string::center | ( | size_t | newlen, |
const char * | left, | ||
const char * | right | ||
) |
string axcel::string::center | ( | size_t | newlen, |
int | left, | ||
int | right | ||
) |
string axcel::string::center | ( | size_t | newlen, |
const char * | pad = " " |
||
) |
string axcel::string::center | ( | size_t | newlen, |
int | pad | ||
) |
string axcel::string::chomp | ( | const char * | eat = "\r\n" | ) |
string axcel::string::chomp | ( | char | c | ) |
string axcel::string::chop | ( | ) |
long axcel::string::chr | ( | int | c, |
size_t | index = 0 |
||
) |
unsigned short axcel::string::cksum | ( | ) |
string & axcel::string::clear | ( | ) |
int axcel::string::cmpinstr | ( | const char * | s, |
... | |||
) |
int axcel::string::cmpleft | ( | const char * | s, |
... | |||
) |
int axcel::string::cmpright | ( | const char * | s, |
... | |||
) |
int axcel::string::cmpstr | ( | const char * | s, |
... | |||
) |
string axcel::string::cntrls | ( | ) |
string axcel::string::cpy | ( | const char * | src, |
size_t | index = 0 , |
||
size_t | count = 0 |
||
) |
string axcel::string::cpy | ( | int | c, |
size_t | index = 0 , |
||
size_t | count = 1 |
||
) |
size_t axcel::string::cspn | ( | const char * | reject, |
size_t | index = 0 |
||
) |
size_t axcel::string::cspn | ( | int | c, |
size_t | index = 0 |
||
) |
string axcel::string::ctypes | ( | int(*)(int) | cfunc | ) |
string axcel::string::ctypes | ( | const char * | chrs | ) |
string axcel::string::cut | ( | ) |
string axcel::string::dec | ( | ) |
string axcel::string::decn | ( | ) |
string axcel::string::digits | ( | ) |
string axcel::string::dup | ( | int | i | ) |
bool axcel::string::empty | ( | ) |
bool axcel::string::ends | ( | const char * | s | ) |
bool axcel::string::ends | ( | int | c | ) |
string axcel::string::esc | ( | const char * | format, |
const char * | chrs | ||
) |
Escape characters.
format | Escaped character format |
chrs | Which characters to escape |
For each character in the string, the character will be replaced using the format string if chrs contains that character. format uses the same format as used by a printf function, except the only token value provided is the value of that character.
This example will replace '%', '$', '&', and '*' characters with "\xAA" where AA is the 2-digit hex number value of the character: mystr.esc("\\x%02x", "$%&*");
string axcel::string::esc | ( | const char * | format, |
int(*)(int) | charfilter = NULL |
||
) |
Escape characters.
format | Escaped character format |
charfilter | Character type function |
For each character in the string, the character will be replaced using the format string if charfilter returns true on that character. format uses the same format as used by a printf function, except the only token value provided is the value of that character.
This example will replace all whitespace characters with "%XX" where XX is the 2 digit hex number value of the character: mystr.esc("%%%02x", isspace)
This next example will replace all punctuation characters with "&#D;"
where D is the decimal number value of the character: mystr.esc("&#%d;", ispunct);
char & axcel::string::front | ( | ) |
string axcel::string::fry | ( | ) |
int axcel::string::getc | ( | ) | [virtual] |
Read byte.
Reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error. Before returning from the method, one of the following methods of the stream must be called:
Reimplemented from axcel::data.
string axcel::string::graphs | ( | ) |
string axcel::string::inc | ( | ) |
string axcel::string::incn | ( | ) |
string axcel::string::ins | ( | size_t | index, |
const char * | str | ||
) |
string axcel::string::ins | ( | size_t | index, |
int | c | ||
) |
bool axcel::string::is | ( | const char * | s | ) |
bool axcel::string::is | ( | int | c | ) |
bool axcel::string::isalnum | ( | ) |
bool axcel::string::isalpha | ( | ) |
bool axcel::string::iscntrl | ( | ) |
bool axcel::string::isctype | ( | int(*)(int) | cfunc | ) |
bool axcel::string::isctype | ( | const char * | chrs | ) |
bool axcel::string::isdigit | ( | ) |
bool axcel::string::isgraph | ( | ) |
bool axcel::string::islower | ( | ) |
bool axcel::string::isprint | ( | ) |
bool axcel::string::ispunct | ( | ) |
bool axcel::string::isspace | ( | ) |
bool axcel::string::isupper | ( | ) |
bool axcel::string::isxdigit | ( | ) |
long axcel::string::itok | ( | size_t | index, |
const char * | delim = " " |
||
) |
index of token
index | Token index |
delim | Delimiting characters |
Returns the index of where the token occurs in this string if it were to be split by delim.
Example:
string mystr = "The quick brown fox"; con.echo(mystr.itok(2, " "))
The above outputs the number 10.
long axcel::string::itok | ( | size_t | index, |
int | delim | ||
) |
index of token
index | Token index |
delim | Delimiting character |
Returns the index of where the token occurs in this string if it were to be split by delim.
Example:
string mystr = "The quick brown fox"; con.echo(mystr.itok(2, ' '))
The above outputs the number 10.
string axcel::string::lc | ( | size_t | start = 0 , |
size_t | count = 0 |
||
) |
string axcel::string::left | ( | size_t | n | ) |
size_t axcel::string::len | ( | ) |
string axcel::string::lowers | ( | ) |
string axcel::string::lpad | ( | size_t | newlen, |
const char * | pad = " " |
||
) |
string axcel::string::lpad | ( | size_t | newlen, |
int | pad | ||
) |
string axcel::string::ltrim | ( | ) |
size_t axcel::string::msize | ( | ) | const |
Resize buffer.
i | Requested size |
Resizes the dynamically allocated character array member buf to fit i or more characters (including the terminating null byte).
Get capacity
string axcel::string::munch | ( | const char * | eat | ) |
string axcel::string::munch | ( | char | c | ) |
size_t axcel::string::nchr | ( | int | ch | ) |
size_t axcel::string::nstr | ( | const char * | str | ) |
size_t axcel::string::ntok | ( | const char * | delim = " " | ) |
size_t axcel::string::ntok | ( | int | delim | ) |
axcel::string::operator char * | ( | ) | [inline, virtual] |
Reimplemented from axcel::data.
axcel::string::operator string | ( | ) | [virtual] |
Convert to string.
The string represenation of this object is the hex values of all the bytes in the internal data buffer delimited by spaces.
Reimplemented from axcel::data.
bool axcel::string::operator!= | ( | char | c | ) |
bool axcel::string::operator!= | ( | const char * | str | ) |
Is not equal?
str | string to compare |
Reimplemented from axcel::data.
string axcel::string::operator() | ( | ) |
string axcel::string::operator* | ( | int | i | ) |
string & axcel::string::operator*= | ( | int | i | ) |
string axcel::string::operator+ | ( | char | c | ) |
string axcel::string::operator+ | ( | const char * | str | ) |
string & axcel::string::operator++ | ( | ) |
string axcel::string::operator++ | ( | int | foo | ) |
string & axcel::string::operator+= | ( | char | c | ) |
string & axcel::string::operator+= | ( | const char * | str | ) |
string axcel::string::operator- | ( | char | c | ) |
string axcel::string::operator- | ( | const char * | str | ) |
string axcel::string::operator-- | ( | int | foo | ) |
string & axcel::string::operator-- | ( | ) |
string & axcel::string::operator-= | ( | const char * | str | ) |
string & axcel::string::operator-= | ( | char | c | ) |
string & axcel::string::operator= | ( | const char * | s | ) |
Reimplemented from axcel::data.
bool axcel::string::operator== | ( | const char * | str | ) |
Is equal?
str | string to compare |
Reimplemented from axcel::data.
bool axcel::string::operator== | ( | char | c | ) |
char & axcel::string::operator[] | ( | int | i | ) |
Reference character.
i | Character index |
Reimplemented from axcel::data.
long axcel::string::pbrk | ( | const char * | accept, |
size_t | index = 0 |
||
) |
string axcel::string::prefix | ( | const char * | str | ) |
string axcel::string::prep | ( | const char * | s, |
size_t | n = 0 |
||
) |
string axcel::string::prep | ( | int | c, |
size_t | n = 1 |
||
) |
string axcel::string::prints | ( | ) |
string axcel::string::puncts | ( | ) |
int axcel::string::putc | ( | int | c | ) | [virtual] |
Write byte.
c | Character to write |
Writes character c to stream and returns a non-negative number on success or EOF on error. Before returning from within this method, one of the following methods must be called:
Reimplemented from axcel::data.
string axcel::string::q | ( | ) |
string axcel::string::qq | ( | ) |
string axcel::string::qx | ( | ) |
string axcel::string::rburn | ( | char | c | ) | [inline] |
Remove starting from last character occurrence.
c | Character to find |
Finds the last occurrence of c, and removes that character and all characters proceeding it in this string.
string axcel::string::rburn | ( | const char * | s | ) | [inline] |
Remove starting from last string occurrence.
s | string to find |
Finds the last occurrence of s, and removes that string and all characters proceeding it in this string.
long axcel::string::rchr | ( | int | c | ) |
string axcel::string::rep | ( | const char * | oldstr, |
const char * | newstr | ||
) |
string axcel::string::rep | ( | int | oldc, |
int | newc | ||
) |
string axcel::string::rev | ( | size_t | start = 0 , |
size_t | count = 0 |
||
) |
string axcel::string::right | ( | size_t | n | ) |
string axcel::string::rm | ( | size_t | index, |
size_t | n | ||
) |
string axcel::string::rol | ( | size_t | i = 1 , |
size_t | index = 0 , |
||
size_t | count = 0 |
||
) |
string axcel::string::ror | ( | size_t | i = 1 , |
size_t | index = 0 , |
||
size_t | count = 0 |
||
) |
string axcel::string::rpad | ( | size_t | newlen, |
const char * | pad = " " |
||
) |
string axcel::string::rpad | ( | size_t | newlen, |
int | pad | ||
) |
long axcel::string::rpbrk | ( | const char * | accept, |
size_t | index = 0 |
||
) |
string axcel::string::rslurp | ( | char | c | ) | [inline] |
Remove up to last character occurrence.
c | Character to find |
Finds the last occurrence of c, and removes that character and all characters preceeding it in this string.
string axcel::string::rslurp | ( | const char * | s | ) | [inline] |
Remove up to first string occurrence.
s | string to find |
Finds the last occurrence of s, and removes that string and all characters preceeding it in this string.
long axcel::string::rstr | ( | const char * | s | ) |
string axcel::string::rtrim | ( | ) |
string axcel::string::shl | ( | size_t | n = 1 | ) |
string axcel::string::shr | ( | size_t | n = 1 | ) |
string axcel::string::slurp | ( | char | c | ) | [inline] |
Remove up to first character occurrence.
c | Character to find |
Finds the first occurrence of c, and removes that character and all characters preceeding it in this string.
string axcel::string::slurp | ( | const char * | s | ) | [inline] |
Remove up to first string occurrence.
s | string to find |
Finds the first occurrence of s, and removes that string and all characters preceeding it in this string.
string axcel::string::spaces | ( | ) |
std::deque< axcel::string > axcel::string::split | ( | const char * | delim = " " | ) |
std::deque< axcel::string > axcel::string::split | ( | int | delim | ) |
size_t axcel::string::spn | ( | int | c, |
size_t | index = 0 |
||
) |
size_t axcel::string::spn | ( | const char * | accept, |
size_t | index = 0 |
||
) |
string axcel::string::squeeze | ( | const char * | chrs = 0 | ) |
string axcel::string::squeeze | ( | int | chr | ) |
bool axcel::string::starts | ( | const char * | s | ) |
bool axcel::string::starts | ( | int | c | ) |
long axcel::string::str | ( | const char * | s, |
size_t | index = 0 |
||
) |
string axcel::string::strip | ( | ) |
string axcel::string::sub | ( | int | n | ) |
string axcel::string::subn | ( | int | n | ) |
string axcel::string::substr | ( | size_t | start, |
size_t | count | ||
) |
string axcel::string::suffix | ( | const char * | str | ) |
string axcel::string::tok | ( | size_t | index, |
int | delim | ||
) |
string axcel::string::tok | ( | size_t | index, |
const char * | delim = " " |
||
) |
string axcel::string::type | ( | ) | [virtual] |
string axcel::string::uc | ( | size_t | start = 0 , |
size_t | count = 0 |
||
) |
string axcel::string::uesc | ( | const char * | format, |
int(*)(int) | charfilter = NULL |
||
) |
Unescape string.
Format | of escaped character |
charfilter | ctype-like function for which character group to unescape |
Matches sub-strings containing the same format as format and replaces them with their real character values. A string escaped using esc("$%3d", iscntrl) can be unescaped using uesc("$%3d", iscntrl). Only characters yielding true from the function charfilter will be unescaped.
string axcel::string::uesc | ( | const char * | format, |
const char * | chrs | ||
) |
Unescape string.
format | Format of escaped character |
chrs | Characters to unescape |
The inverse of esc(). Matches sub-strings containing the same format as format and replaces them with their real character values. A string escaped using esc("<%d>", "~!@#$") can be unescaped using uesc("<%d>", "~!@#$"). Only characters specified in chrs will be unescaped.
string axcel::string::untag | ( | int | opentag = '<' , |
int | closetag = '>' |
||
) |
string axcel::string::uppers | ( | ) |
string axcel::string::wrap | ( | size_t | len, |
const char * | eol = "\r\n" |
||
) |
string axcel::string::xdigits | ( | ) |