#include <str.hpp>
Public Member Functions | |
int | getLen () const |
int | getCapacity () const |
bool | reserve (int n) |
reserves memory to hold n characters More... | |
void | clear () |
Clears the string by putting NULL terminator at 1st char. More... | |
void | clearAll () |
Zeroes out ALL memory that belongs to this str. More... | |
void | toLower () |
Make every alphabet character lowercase. More... | |
void | toUpper () |
Make every alphabet character uppercase. More... | |
int | printf (const char *pFormat,...) |
int | scanf (const char *pFormat,...) |
int | tokenize (const char *delimators, int char_ptr_count,...) |
const str * | getToken (const char *pSplitter=" ", bool restart=false) |
void | operator+= (const char singleChar) |
Append char using += Operator. More... | |
void | operator+= (const char *pString) |
Append String using += Operator. More... | |
void | operator+= (const str &s) |
Append str to us. More... | |
void | operator+= (int n) |
Subtract Integer using += Operator if string is an integer value. More... | |
void | operator-= (const char *pString) |
Remove all instances of pString using -= Operator. More... | |
void | operator-= (const str &s) |
Remove (erase) str from us. More... | |
void | operator-= (int n) |
Subtract Integer String using if string is an integer value. More... | |
void | operator+= (float n) |
Subtract Float using += Operator if string is an float value. More... | |
void | operator-= (float n) |
Subtract Float String using -= Operator if string is an float value. More... | |
const char * | operator() () const |
() Operator (without a name): Ex: puts(myCStr()); More... | |
const char * | c_str () const |
operator float () const | |
Get c-string pointer (calls operator above) More... | |
operator int () const | |
(int) Cast Operator: Ex: int x = (int)myCStr; More... | |
char & | operator[] (int pos) |
Index Operator to get and set value @ Index. More... | |
Constructors (and destructor) | |
External memory constructor will be unable to allocate more memory and will fail to grow the string greater than the size | |
str () | |
Default constructor. More... | |
str (int capacity) | |
Constructor with initial capacity. More... | |
str (const char *pString) | |
Construct from char* pointer. More... | |
str (char *buff, int size) | |
Construct to use external memory. More... | |
str (const str &s) | |
Copy Constructor. More... | |
~str () | |
Destructor. More... | |
Insertion functions | |
bool | insertAtBeg (const char *pString) |
bool | insertAtBeg (const str &s) |
bool | insertAtEnd (const char *pString) |
bool | insertAtEnd (const str &s) |
bool | insertAt (const int index, const char *pString) |
bool | insertAt (const int index, const str &s) |
Append functions | |
void | append (const char *pString) |
Appends constant string pointer. More... | |
void | append (const str &s) |
Appends another str. More... | |
void | append (int x) |
Appends integer as characters. More... | |
void | append (float x) |
Appends float as characters. More... | |
void | appendAsHex (unsigned int num) |
Appends as hexadecimal ie: DEADBEEF. More... | |
Comparison functions | |
| |
bool | compareTo (const char *pString) const |
bool | compareTo (const str &s) const |
bool | compareToIgnoreCase (const char *pString) const |
bool | compareToIgnoreCase (const str &s) const |
Get Word Index Functions | |
int | firstIndexOfIgnoreCase (const char *pString) const |
int | firstIndexOfIgnoreCase (const str &s) const |
int | firstIndexOf (const char *pString) const |
int | firstIndexOf (const str &s) const |
int | lastIndexOf (const char *pString) const |
int | lastIndexOf (const str &s) const |
Functions to check a contained string | |
bool | contains (const char *pString) const |
bool | contains (const str &s) const |
bool | containsIgnoreCase (const char *pString) const |
bool | containsIgnoreCase (const str &s) const |
int | countOf (const char *pString) const |
int | countOf (const str &s) const |
bool | beginsWith (const char *pString) const |
bool | beginsWith (const str &s) const |
bool | beginsWithIgnoreCase (const char *pString) const |
bool | beginsWithIgnoreCase (const str &s) const |
bool | beginsWithWholeWord (const char *pString, char seperator=' ') const |
bool | beginsWithWholeWordIgnoreCase (const char *pString, char seperator=' ') const |
bool | endsWith (const char *pString) const |
bool | endsWith (const str &s) const |
bool | endsWithIgnoreCase (const char *pString) const |
bool | endsWithIgnoreCase (const str &s) const |
Erase Functions | |
bool | erase (const char *pString) |
bool | erase (const str &s) |
bool | eraseFirst (int nChars) |
bool | eraseLast (int nChars) |
bool | eraseCharAt (int index) |
bool | eraseAllAfter (int index) |
bool | eraseAfter (int index, int nChars) |
bool | eraseFirstWords (int words, char separator= ' ') |
int | eraseAllSpecialChars () |
Erase all characters except alphabets and numerals. More... | |
Trimming Functions to remove leading or trailing character sets | |
Example: str s("...Hello..;;''"); s.trimEnd(".;'"); –> s is now: "...Hello" | |
void | trimStart (const char *pChars) |
void | trimStart (const str &s) |
void | trimEnd (const char *pChars) |
void | trimEnd (const str &s) |
Find & Replace Functions | |
bool | replaceFirst (const char *pFind, const char *pWith) |
bool | replaceLast (const char *pFind, const char *pWith) |
int | replaceAll (const char *pFind, const char *pWith) |
Sub-string Functions | |
| |
const str & | subString (int fromIndex) |
const str & | subString (int fromIndex, int charCount) |
const str & | subString (char fromFirstChar) |
const str & | subString (const char *fromStr) |
const str & | subString (char fromFirstChar, int charCount) |
const str & | subString (const char *fromStr, int charCount) |
const str & | subString (char fromFirstChar, char toLastChar) |
Datatype detection Functions | |
bool | isAllAlpha () const |
bool | isAlphaNumeric () const |
bool | isFloat () const |
bool | isUint () const |
bool | isInt () const |
Checksum Functions | |
unsigned int | checksum_Get () |
Get integer value of XOR checksum of this string. More... | |
void | checksum_Append () |
Appends checksum characters: Ex: 123 becomes: 123:0A. More... | |
void | checksum_Remove () |
Removes checksum characters: Ex: 123:0A becomes 123. More... | |
bool | checksum_Verify () |
Assignment Operators | |
void | operator= (const char *pString) |
Assign a string: myCStr = "123";. More... | |
void | operator= (int num) |
Assign an int : myCStr = 123;. More... | |
void | operator= (float num) |
Assign a float: myCStr = 1.23;. More... | |
str & | operator= (const str &rhs) |
Assign Operator for str a = str b. More... | |
Increment & Decrement Operators if the string consist of integer value | |
void | operator++ () |
Pre-Increment if String is an integer. More... | |
void | operator++ (int unused) |
Post-Increment if String is an integer. More... | |
void | operator-- () |
Pre-Decrement if String is an integer. More... | |
void | operator-- (int unused) |
Post-Decrement if String is an integer. More... | |
Equality Operators | |
bool | operator== (const char *pString) const |
bool | operator== (const str &rhs) const |
bool | operator== (int) const |
bool | operator!= (const char *pString) const |
bool | operator!= (const str &rhs) const |
bool | operator!= (int) const |
Comparison Operators to perform comparisons, such as: | |
str s; s = "hello"; if(s < "helloo") ... s = 123; if(s < 1234) ... s = 1.23; if(s >= 1.22) ... | |
bool | operator< (const char *pString) const |
bool | operator< (const str &s) const |
bool | operator< (int) const |
bool | operator> (const char *pString) const |
bool | operator> (int) const |
bool | operator> (const str &s) const |
bool | operator<= (const char *pString) const |
bool | operator<= (int) const |
bool | operator<= (const str &s) const |
bool | operator>= (const char *pString) const |
bool | operator>= (int) const |
bool | operator>= (const str &s) const |
bool | operator< (float) const |
bool | operator>= (float) const |
bool | operator> (float) const |
bool | operator<= (float) const |
Static Public Member Functions | |
Static conversion functions from string to int and float | |
| |
static int | toInt (const char *pString) |
Static method to convert char* string to integer. More... | |
static int | toInt (str &s) |
static float | toFloat (const char *pString) |
Static method to convert char* string to float. More... | |
static float | toFloat (str &s) |
Friends | |
bool | test_str (void) |
For tests : More... | |
Detailed Description
Custom string class
str class can provide many string manipulation functions while maintaining internal memory and allocating more memory when needed.
You can also printf to this str object:
Parsing (Tokenize) Example:
Note that the original str s is not destroyed during tokenize operations
Constructor & Destructor Documentation
str::str | ( | ) |
Default constructor.
str::str | ( | int | capacity | ) |
Constructor with initial capacity.
str::str | ( | const char * | pString | ) |
Construct from char* pointer.
str::str | ( | char * | buff, |
int | size | ||
) |
Construct to use external memory.
Cannot call init() for this constructor.
str::str | ( | const str & | s | ) |
Copy Constructor.
str::~str | ( | ) |
Destructor.
Member Function Documentation
void str::append | ( | const char * | pString | ) |
Appends constant string pointer.
|
inline |
Appends another str.
void str::append | ( | int | x | ) |
Appends integer as characters.
void str::append | ( | float | x | ) |
Appends float as characters.
void str::appendAsHex | ( | unsigned int | num | ) |
Appends as hexadecimal ie: DEADBEEF.
bool str::beginsWith | ( | const char * | pString | ) | const |
|
inline |
bool str::beginsWithIgnoreCase | ( | const char * | pString | ) | const |
|
inline |
bool str::beginsWithWholeWord | ( | const char * | pString, |
char | seperator = ' ' |
||
) | const |
Checks if the string begins with a whole word. If str = "Hello World", then str.beginsWithWholdWord("Hello") will be true But if str = "HelloWorld" then this will be false because this function will check whole word separated by space char unless the separator itself is provided.
bool str::beginsWithWholeWordIgnoreCase | ( | const char * | pString, |
char | seperator = ' ' |
||
) | const |
|
inline |
void str::checksum_Append | ( | ) |
Appends checksum characters: Ex: 123 becomes: 123:0A.
unsigned int str::checksum_Get | ( | ) |
Get integer value of XOR checksum of this string.
void str::checksum_Remove | ( | ) |
Removes checksum characters: Ex: 123:0A becomes 123.
bool str::checksum_Verify | ( | ) |
- Returns
- TRUE if for example: actual checksum 0A matches calculated 0A of string "123"
void str::clear | ( | void | ) |
Clears the string by putting NULL terminator at 1st char.
void str::clearAll | ( | ) |
Zeroes out ALL memory that belongs to this str.
bool str::compareTo | ( | const char * | pString | ) | const |
|
inline |
bool str::compareToIgnoreCase | ( | const char * | pString | ) | const |
|
inline |
bool str::contains | ( | const char * | pString | ) | const |
|
inline |
bool str::containsIgnoreCase | ( | const char * | pString | ) | const |
|
inline |
int str::countOf | ( | const char * | pString | ) | const |
|
inline |
bool str::endsWith | ( | const char * | pString | ) | const |
|
inline |
bool str::endsWithIgnoreCase | ( | const char * | pString | ) | const |
|
inline |
bool str::erase | ( | const char * | pString | ) |
|
inline |
bool str::eraseAfter | ( | int | index, |
int | nChars | ||
) |
bool str::eraseAllAfter | ( | int | index | ) |
int str::eraseAllSpecialChars | ( | ) |
Erase all characters except alphabets and numerals.
bool str::eraseCharAt | ( | int | index | ) |
bool str::eraseFirst | ( | int | nChars | ) |
bool str::eraseFirstWords | ( | int | words, |
char | separator = ' ' |
||
) |
bool str::eraseLast | ( | int | nChars | ) |
int str::firstIndexOf | ( | const char * | pString | ) | const |
|
inline |
int str::firstIndexOfIgnoreCase | ( | const char * | pString | ) | const |
|
inline |
int str::getCapacity | ( | ) | const |
- Returns
- the current allocated capacity of str
int str::getLen | ( | ) | const |
- Returns
- Number of characters in the string
const str * str::getToken | ( | const char * | pSplitter = " " , |
bool | restart = false |
||
) |
Tokenize function
- Parameters
-
pSplitter The tokens that mark the end of the token to get. restart Restarts tokenize operation on contents of this str. This optional parameter is not needed after restarting 1st tokenize operation.
- Returns
- Pointer to substring, or NULL if no more tokens remain
- Note
- Unlike strtok(), the contents of this str is not destroyed.
- Warning
- The returned substring pointer is temporary, and further calls to this function will re-use the same substr, so copy the returned substring if it is to be used later.
Example:
bool str::insertAt | ( | const int | index, |
const char * | pString | ||
) |
|
inline |
bool str::insertAtBeg | ( | const char * | pString | ) |
|
inline |
bool str::insertAtEnd | ( | const char * | pString | ) |
|
inline |
bool str::isAllAlpha | ( | ) | const |
- Returns
- TRUE if the string is all alphabetical characters only
bool str::isAlphaNumeric | ( | ) | const |
- Returns
- TRUE if the string is all alpha or numerical characters only
bool str::isFloat | ( | ) | const |
- Returns
- TRUE if the string is a floating point number
bool str::isInt | ( | ) | const |
- Returns
- TRUE if the string is a number
bool str::isUint | ( | ) | const |
- Returns
- TRUE if the string is an unsigned number
int str::lastIndexOf | ( | const char * | pString | ) | const |
|
inline |
str::operator float | ( | ) | const |
Get c-string pointer (calls operator above)
(float) Cast Operator: Ex: float x = (float)myCStr;
str::operator int | ( | ) | const |
(int) Cast Operator: Ex: int x = (int)myCStr;
bool str::operator!= | ( | const char * | pString | ) | const |
bool str::operator!= | ( | const str & | rhs | ) | const |
bool str::operator!= | ( | int | n | ) | const |
const char * str::operator() | ( | ) | const |
() Operator (without a name): Ex: puts(myCStr());
void str::operator++ | ( | ) |
Pre-Increment if String is an integer.
void str::operator++ | ( | int | unused | ) |
Post-Increment if String is an integer.
void str::operator+= | ( | const char | singleChar | ) |
Append char using += Operator.
Add/Subtract Operators:
void str::operator+= | ( | const char * | pString | ) |
Append String using += Operator.
void str::operator+= | ( | const str & | s | ) |
Append str to us.
void str::operator+= | ( | int | n | ) |
Subtract Integer using += Operator if string is an integer value.
void str::operator+= | ( | float | n | ) |
Subtract Float using += Operator if string is an float value.
void str::operator-- | ( | ) |
Pre-Decrement if String is an integer.
void str::operator-- | ( | int | unused | ) |
Post-Decrement if String is an integer.
void str::operator-= | ( | const char * | pString | ) |
Remove all instances of pString using -= Operator.
void str::operator-= | ( | const str & | s | ) |
Remove (erase) str from us.
void str::operator-= | ( | int | n | ) |
Subtract Integer String using if string is an integer value.
void str::operator-= | ( | float | n | ) |
Subtract Float String using -= Operator if string is an float value.
bool str::operator< | ( | const char * | pString | ) | const |
|
inline |
bool str::operator< | ( | int | x | ) | const |
bool str::operator< | ( | float | x | ) | const |
bool str::operator<= | ( | const char * | pString | ) | const |
bool str::operator<= | ( | int | x | ) | const |
|
inline |
bool str::operator<= | ( | float | x | ) | const |
void str::operator= | ( | const char * | pString | ) |
Assign a string: myCStr = "123";.
void str::operator= | ( | int | num | ) |
Assign an int : myCStr = 123;.
void str::operator= | ( | float | num | ) |
Assign a float: myCStr = 1.23;.
bool str::operator== | ( | const char * | pString | ) | const |
bool str::operator== | ( | const str & | rhs | ) | const |
bool str::operator== | ( | int | n | ) | const |
bool str::operator> | ( | const char * | pString | ) | const |
bool str::operator> | ( | int | x | ) | const |
|
inline |
bool str::operator> | ( | float | x | ) | const |
bool str::operator>= | ( | const char * | pString | ) | const |
bool str::operator>= | ( | int | x | ) | const |
|
inline |
bool str::operator>= | ( | float | x | ) | const |
char & str::operator[] | ( | int | pos | ) |
Index Operator to get and set value @ Index.
int str::printf | ( | const char * | pFormat, |
... | |||
) |
Similar to printf, but will print data into the string
- Returns
- The number of characters printed
int str::replaceAll | ( | const char * | pFind, |
const char * | pWith | ||
) |
bool str::replaceFirst | ( | const char * | pFind, |
const char * | pWith | ||
) |
bool str::replaceLast | ( | const char * | pFind, |
const char * | pWith | ||
) |
bool str::reserve | ( | int | n | ) |
reserves memory to hold n characters
int str::scanf | ( | const char * | pFormat, |
... | |||
) |
Similar to scanf but scans from this str
- Returns
- The number of parameters successfully parsed
- Note
- Using %*s will scan a string and ignore it.
- Deliminator by default is a space, read "sscanf()" documentation online for more references.
Example:
const str & str::subString | ( | int | fromIndex | ) |
const str & str::subString | ( | int | fromIndex, |
int | charCount | ||
) |
const str & str::subString | ( | char | fromFirstChar | ) |
const str & str::subString | ( | const char * | fromStr | ) |
const str & str::subString | ( | char | fromFirstChar, |
int | charCount | ||
) |
const str & str::subString | ( | const char * | fromStr, |
int | charCount | ||
) |
const str & str::subString | ( | char | fromFirstChar, |
char | toLastChar | ||
) |
|
static |
Static method to convert char* string to float.
|
inlinestatic |
|
static |
Static method to convert char* string to integer.
|
inlinestatic |
int str::tokenize | ( | const char * | delimators, |
int | char_ptr_count, | ||
... | |||
) |
Perform string tokenization (original copy is destroyed) If you want to get pointers separating the string such as "hello world 123", then you can use this function, however, your original string will be destroyed.
void str::toLower | ( | ) |
Make every alphabet character lowercase.
void str::toUpper | ( | ) |
Make every alphabet character uppercase.
void str::trimEnd | ( | const char * | pChars | ) |
|
inline |
void str::trimStart | ( | const char * | pChars | ) |
|
inline |
Friends And Related Function Documentation
|
friend |
For tests :
The documentation for this class was generated from the following files: