#include <String.h>
Inheritance diagram for clawsoft::String:
Many times when we work with strings we leave BIG memory leaks in our programs, the main idea here is to help the programmer by providing here a very complete strig treatment tool for everyday use.
TODO reimplement all conversions and use the fastest algorithms possible, if you think that is possible to use standard C library conversion functions and that his functions as portable across al platforms targeted, then use them as needed.
Public Methods | |
String () | |
Default constructor, it initializes buffer and len to zero. | |
String (String &s) | |
transforms and concatenates s to the current String | |
String (const char *s) | |
This constructor initializes an instance of this class by taking an array of chars. | |
String (const int n) | |
This constructor initializes an instance of this class by transforming an integer to an array of chars and then calling assign(const char *s);. | |
String (const unsigned int n) | |
This constructor initializes an instance of this class by transforming an unsigned integer to an array of chars and then calling assign(const char *s);. | |
String (const float n) | |
This constructor initializes an instance of this class by transforming a float to an array of chars and then calling assign(const char *s);. | |
String (const double n) | |
This constructor initializes an instance of this class by transforming a double to an array of chars and then calling assign(const char *s);. | |
String (const long double n) | |
This constructor initializes an instance of this class by transforming a long double to an array of chars and then calling assign(const char *s);. | |
String (const Sint64 n) | |
This constructor initializes an instance of this class by transforming a Sint64 to an array of chars and then calling assign(const char *s);. | |
~String () | |
Destructor, eliminates the contents of buffer and sets len to zero by calling the method destroy();. | |
void | assign (const char *s) |
Assigns the contents of s to buffer. | |
void | assign (const int n) |
Transforms and concatenates n to the current String. | |
void | assign (const unsigned int n) |
Transforms and concatenates n to the current String. | |
void | assign (const float n) |
Transforms and concatenates n to the current String. | |
void | assign (const double n) |
Transforms and concatenates n to the current String. | |
void | assign (const long double n) |
Transforms and concatenates n to the current String. | |
void | assign (const Sint64 n) |
Transforms and concatenates n to the current String. | |
const char * | toCharPtr () |
returns a pointer to buffer | |
void | concat (const char *s) |
transforms and concatenates s to the current String | |
void | concat (String &s) |
transforms and concatenates s to the current String | |
void | concat (const int n) |
transforms and concatenates n to the current String | |
void | concat (const unsigned int n) |
transforms and concatenates n to the current String | |
void | concat (const float n) |
transforms and concatenates n to the current String | |
void | concat (const double n) |
transforms and concatenates n to the current String | |
void | concat (const long double n) |
transforms and concatenates n to the current String | |
void | concat (const Sint64 n) |
transforms and concatenates n to the current String | |
void | concat (const Uint64 n) |
transforms and concatenates n to the current String | |
String & | operator= (const char *s) |
Assigns s to buffer by calling assign(const char *);. | |
String & | operator= (const int n) |
Transforms n and assigns it to buffer by calling assign(const char *);. | |
String & | operator= (const unsigned int n) |
Transforms n and assigns it to buffer by calling assign(const char *);. | |
String & | operator= (const float n) |
Transforms n and assigns it to buffer by calling assign(const char *);. | |
String & | operator= (const double n) |
Transforms n and assigns it to buffer by calling assign(const char *);. | |
String & | operator= (const long double n) |
Transforms n and assigns it to buffer by calling assign(const char *);. | |
String & | operator= (const Sint64 n) |
Transforms n and assigns it to buffer by calling assign(const char *);. | |
String & | operator+ (String &s) |
Concatenates s to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+ (const char *s) |
Concatenates s to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+ (const int n) |
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+ (const unsigned int n) |
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+ (const float n) |
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+ (const double n) |
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+ (const long double n) |
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+ (const Sint64 n) |
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+ (const Uint64 n) |
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself. | |
String & | operator+= (String &s) |
Concatenates s to itself. | |
String & | operator+= (const char *s) |
Concatenates s to itself. | |
String & | operator+= (const int n) |
Transforms n and concatenates it to the current String. | |
String & | operator+= (const unsigned int n) |
Transforms n and concatenates it to the current String. | |
String & | operator+= (const float n) |
Transforms n and concatenates it to the current String. | |
String & | operator+= (const double n) |
Transforms n and concatenates it to the current String. | |
String & | operator+= (const long double n) |
Transforms n and concatenates it to the current String. | |
String & | operator+= (const Sint64 n) |
Transforms n and concatenates it to the current String. | |
String & | operator+= (const Uint64 n) |
Transforms n and concatenates it to the current String. | |
const char | charAt (int i) |
Returns the character at position i. | |
const char | operator[] (int i) |
Returns the character at position i by overriding the operator[]. | |
void | deleteString () |
This just calls destroy, so you can delete the contents in buffer without the need of delete the object itself. | |
String & | trimLeft (const char c= ' ') |
Eliminates all ocurrences of the c character that appears at left of the string. | |
String & | trimRight (const char c= ' ') |
Eliminates all ocurrences of the c character that appears at right of the string. | |
String & | trim (const char c= ' ') |
Eliminates all ocurrences of the c character that appears at the beginning and the end of the string. | |
String & | toUpperCase () |
Transforms the string to uppercase letters only. | |
String & | toLowerCase () |
Transforms the string to lowercase letters only. | |
const unsigned int | lenght () |
Returns the lenght of the string which is stored in len. | |
const unsigned int | size () |
Returns the lenght of the string which is stored in len. | |
const int | toInt () |
Transforms the contents of the string to an integer if the string can't be translated to a number then the exception NumberException is thrown. | |
const unsigned int | toUInt () |
Transforms the contents of the string to an unsigned integer if the string can't be translated to a number then the exception NumberException is thrown. | |
const float | toFloat () |
Transforms the contents of the string to a float if the string can't be translated to a number then the exception NumberException is thrown. | |
const double | toDouble () |
Transforms the contents of the string to a double if the string can't be translated to a number then the exception NumberException is thrown. | |
const long double | toLongDouble () |
Transforms the contents of the string to a long double if the string can't be translated to a number then the exception NumberException is thrown. | |
const Sint64 | toInt64 () |
Transforms the contents of the string to a Sint64 if the string can't be translated to a number then the exception NumberException is thrown. | |
bool | operator== (const String &s) |
Checks if the parameter s is equal to buffer. | |
bool | operator== (const char *s) |
Checks if the parameter s is equal to buffer. | |
bool | operator== (const int n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | operator== (const unsigned int n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | operator== (const float n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | operator== (const double n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | operator== (const long double n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | operator== (const Sint64 n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | equals (const String &s) |
Checks if the parameter s is equal to buffer. | |
bool | equals (const char *s) |
Checks if the parameter s is equal to buffer. | |
bool | equals (const int n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | equals (const unsigned int n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | equals (const float n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | equals (const double n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | equals (const long double n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | equals (const Sint64 n) |
Transforms and checks if the parameter n is equal to buffer. | |
bool | hasSubstring (String &s) |
Tells if the substring s is inside the current String. | |
bool | hasSubstring (const char *s) |
Tells if the substring s is inside the current String. | |
String & | deleteFirst () |
Deletes the first character in buffer. | |
String & | deleteLast () |
Deletes the last character in buffer. | |
const int | index (String &s, int start=0) |
Returns the leftmost position for string s inside buffer starting at byte start. | |
const int | index (const char *s, int start=0) |
Returns the leftmost position for string s inside buffer starting at byte start. | |
const int | index (const char c, int start=0) |
Returns the leftmost position for string s inside buffer starting at byte start. | |
const int | rindex (String &s, int end=0) |
Returns the rightmost position for string s inside buffer starting at byte end from right to left. | |
const int | rindex (const char *s, int end=0) |
Returns the rightmost position for string s inside buffer starting at byte end from right to left. | |
const int | rindex (const char c, int end=0) |
Returns the rightmost position for string s inside buffer starting at byte end from right to left. | |
bool | startsWith (String &s) |
This method checks if the current string starts with the string stored in s. | |
bool | startsWith (const char *s) |
This method checks if the current string starts with the string stored in s. | |
bool | startsIWith (const char *s) |
This method checks if the current string starts with the string stored in s without taking care if s is uppercase or no. | |
bool | endsWith (String &s) |
This method checks if the current string ends with the string stored in s. | |
bool | endsWith (const char *s) |
This method checks if the current string ends with the string stored in s. | |
String & | deleteCharAt (const int pos) |
With this you can delete a character at a given position pos, positions start at 0. | |
String & | insertCharAt (const int pos, const char c) |
Use this method when you need to add a given character c at position pos. | |
const char * | getClassName () |
Returns the name of the current class. | |
Static Public Methods | |
bool | equals (const String &s1, const String &s2) |
Checks if the parameter s1 is equal to s2. | |
int | installedCPUs () |
This will return how many CPUs are installed in the system. | |
double | cpuSpeed () |
This will return the CPU speed in megahertz. | |
int | totalMemory () |
Will return the total amount of system memory. | |
int | freeMemory () |
Will return the total amount of free system memory. | |
void | usleep (Uint32 usec) |
Will freeze the software for usec microseconds. | |
Protected Methods | |
void | setClassName (const char *n) |
Call this method when you need to set the name of the class you're creating, typically in it's constructor, remember that you must set the classname for every class you create, that way you can have more information while debugging. | |
Private Methods | |
void | destroy () |
Eliminates the contents of buffer and sets len to zero. | |
Private Attributes | |
char * | buffer |
Holds the string itself as and array of chars by default it points to null which also means empty String. | |
int | len |
Holds the dimensions of the string plus one, the reserved address is for storing the termination character \0. | |
Friends | |
std::ostream & | operator<< (std::ostream &stream, String s) |
The main idea behind this is take advantage of the << operator of the ostream class, this way, you can use this class with streams String a = "hello world"; you would normally do: cout << a.toCharPtr() << endl; with this operator you can just: cout << a << endl;. |
|
Default constructor, it initializes buffer and len to zero.
|
|
transforms and concatenates s to the current String
|
|
This constructor initializes an instance of this class by taking an array of chars.
|
|
This constructor initializes an instance of this class by transforming an integer to an array of chars and then calling assign(const char *s);.
|
|
This constructor initializes an instance of this class by transforming an unsigned integer to an array of chars and then calling assign(const char *s);.
|
|
This constructor initializes an instance of this class by transforming a float to an array of chars and then calling assign(const char *s);.
|
|
This constructor initializes an instance of this class by transforming a double to an array of chars and then calling assign(const char *s);.
|
|
This constructor initializes an instance of this class by transforming a long double to an array of chars and then calling assign(const char *s);.
|
|
This constructor initializes an instance of this class by transforming a Sint64 to an array of chars and then calling assign(const char *s);.
|
|
Destructor, eliminates the contents of buffer and sets len to zero by calling the method destroy();.
|
|
Transforms and concatenates n to the current String.
|
|
Transforms and concatenates n to the current String.
|
|
Transforms and concatenates n to the current String.
|
|
Transforms and concatenates n to the current String.
|
|
Transforms and concatenates n to the current String.
|
|
Transforms and concatenates n to the current String.
|
|
Assigns the contents of s to buffer.
|
|
Returns the character at position i.
|
|
transforms and concatenates n to the current String
|
|
transforms and concatenates n to the current String
|
|
transforms and concatenates n to the current String
|
|
transforms and concatenates n to the current String
|
|
transforms and concatenates n to the current String
|
|
transforms and concatenates n to the current String
|
|
transforms and concatenates n to the current String
|
|
transforms and concatenates s to the current String
|
|
transforms and concatenates s to the current String
|
|
This will return the CPU speed in megahertz.
|
|
With this you can delete a character at a given position pos, positions start at 0.
|
|
Deletes the first character in buffer.
|
|
Deletes the last character in buffer.
|
|
This just calls destroy, so you can delete the contents in buffer without the need of delete the object itself.
|
|
Eliminates the contents of buffer and sets len to zero.
|
|
This method checks if the current string ends with the string stored in s.
|
|
This method checks if the current string ends with the string stored in s.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Checks if the parameter s is equal to buffer.
|
|
Checks if the parameter s is equal to buffer.
|
|
Checks if the parameter s1 is equal to s2.
|
|
Will return the total amount of free system memory.
|
|
Returns the name of the current class.
|
|
Tells if the substring s is inside the current String.
|
|
Tells if the substring s is inside the current String.
|
|
Returns the leftmost position for string s inside buffer starting at byte start.
|
|
Returns the leftmost position for string s inside buffer starting at byte start.
|
|
Returns the leftmost position for string s inside buffer starting at byte start.
|
|
Use this method when you need to add a given character c at position pos.
|
|
This will return how many CPUs are installed in the system.
|
|
Returns the lenght of the string which is stored in len.
|
|
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.
|
|
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.
|
|
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.
|
|
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.
|
|
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.
|
|
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.
|
|
Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.
|
|
Concatenates s to the current String by overriding the + operator returning an instance of itself.
|
|
Concatenates s to the current String by overriding the + operator returning an instance of itself.
|
|
Transforms n and concatenates it to the current String.
|
|
Transforms n and concatenates it to the current String.
|
|
Transforms n and concatenates it to the current String.
|
|
Transforms n and concatenates it to the current String.
|
|
Transforms n and concatenates it to the current String.
|
|
Transforms n and concatenates it to the current String.
|
|
Transforms n and concatenates it to the current String.
|
|
Concatenates s to itself.
|
|
Concatenates s to itself.
|
|
Transforms n and assigns it to buffer by calling assign(const char *);.
|
|
Transforms n and assigns it to buffer by calling assign(const char *);.
|
|
Transforms n and assigns it to buffer by calling assign(const char *);.
|
|
Transforms n and assigns it to buffer by calling assign(const char *);.
|
|
Transforms n and assigns it to buffer by calling assign(const char *);.
|
|
Transforms n and assigns it to buffer by calling assign(const char *);.
|
|
Assigns s to buffer by calling assign(const char *);.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Transforms and checks if the parameter n is equal to buffer.
|
|
Checks if the parameter s is equal to buffer.
|
|
Checks if the parameter s is equal to buffer.
|
|
Returns the character at position i by overriding the operator[].
|
|
Returns the rightmost position for string s inside buffer starting at byte end from right to left.
|
|
Returns the rightmost position for string s inside buffer starting at byte end from right to left.
|
|
Returns the rightmost position for string s inside buffer starting at byte end from right to left.
|
|
Call this method when you need to set the name of the class you're creating, typically in it's constructor, remember that you must set the classname for every class you create, that way you can have more information while debugging.
|
|
Returns the lenght of the string which is stored in len.
|
|
This method checks if the current string starts with the string stored in s without taking care if s is uppercase or no.
|
|
This method checks if the current string starts with the string stored in s.
|
|
This method checks if the current string starts with the string stored in s.
|
|
returns a pointer to buffer
|
|
Transforms the contents of the string to a double if the string can't be translated to a number then the exception NumberException is thrown.
|
|
Transforms the contents of the string to a float if the string can't be translated to a number then the exception NumberException is thrown.
|
|
Transforms the contents of the string to an integer if the string can't be translated to a number then the exception NumberException is thrown.
|
|
Transforms the contents of the string to a Sint64 if the string can't be translated to a number then the exception NumberException is thrown.
|
|
Transforms the contents of the string to a long double if the string can't be translated to a number then the exception NumberException is thrown.
|
|
Transforms the string to lowercase letters only.
|
|
Will return the total amount of system memory.
|
|
Transforms the contents of the string to an unsigned integer if the string can't be translated to a number then the exception NumberException is thrown.
|
|
Transforms the string to uppercase letters only.
|
|
Eliminates all ocurrences of the c character that appears at the beginning and the end of the string.
|
|
Eliminates all ocurrences of the c character that appears at left of the string.
|
|
Eliminates all ocurrences of the c character that appears at right of the string.
|
|
Will freeze the software for usec microseconds.
|
|
The main idea behind this is take advantage of the << operator of the ostream class, this way, you can use this class with streams
|
|
Holds the string itself as and array of chars by default it points to null which also means empty String.
|
|
Holds the dimensions of the string plus one, the reserved address is for storing the termination character \0.
|
Authors:
Juan V. Guerrero
Jannette C. Mejia
Juan C. Guevara
Powered by: