Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

clawsoft::String Class Reference

#include <String.h>

Inheritance diagram for clawsoft::String:

Inheritance graph
[legend]
Collaboration diagram for clawsoft::String:

Collaboration graph
[legend]

Detailed Description

This a string treatment class, it has a lot of methods and the main idea is eliminate de use of the common tricks we use everyday while we work with strings.

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;.



Constructor & Destructor Documentation

clawsoft::String::String  
 

Default constructor, it initializes buffer and len to zero.

clawsoft::String::String String &    s
 

transforms and concatenates s to the current String

clawsoft::String::String const char *    s
 

This constructor initializes an instance of this class by taking an array of chars.

clawsoft::String::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);.

clawsoft::String::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);.

clawsoft::String::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);.

clawsoft::String::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);.

clawsoft::String::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);.

clawsoft::String::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);.

clawsoft::String::~String  
 

Destructor, eliminates the contents of buffer and sets len to zero by calling the method destroy();.


Member Function Documentation

void clawsoft::String::assign const Sint64    n
 

Transforms and concatenates n to the current String.

void clawsoft::String::assign const long double    n
 

Transforms and concatenates n to the current String.

void clawsoft::String::assign const double    n
 

Transforms and concatenates n to the current String.

void clawsoft::String::assign const float    n
 

Transforms and concatenates n to the current String.

void clawsoft::String::assign const unsigned int    n
 

Transforms and concatenates n to the current String.

void clawsoft::String::assign const int    n
 

Transforms and concatenates n to the current String.

void clawsoft::String::assign const char *    s
 

Assigns the contents of s to buffer.

const char clawsoft::String::charAt int    i
 

Returns the character at position i.

void clawsoft::String::concat const Uint64    n
 

transforms and concatenates n to the current String

void clawsoft::String::concat const Sint64    n
 

transforms and concatenates n to the current String

void clawsoft::String::concat const long double    n
 

transforms and concatenates n to the current String

void clawsoft::String::concat const double    n
 

transforms and concatenates n to the current String

void clawsoft::String::concat const float    n
 

transforms and concatenates n to the current String

void clawsoft::String::concat const unsigned int    n
 

transforms and concatenates n to the current String

void clawsoft::String::concat const int    n
 

transforms and concatenates n to the current String

void clawsoft::String::concat String &    s
 

transforms and concatenates s to the current String

void clawsoft::String::concat const char *    s
 

transforms and concatenates s to the current String

double clawsoft::System::cpuSpeed   [static, inherited]
 

This will return the CPU speed in megahertz.

String & clawsoft::String::deleteCharAt const int    pos
 

With this you can delete a character at a given position pos, positions start at 0.

String & clawsoft::String::deleteFirst  
 

Deletes the first character in buffer.

String & clawsoft::String::deleteLast  
 

Deletes the last character in buffer.

void clawsoft::String::deleteString  
 

This just calls destroy, so you can delete the contents in buffer without the need of delete the object itself.

void clawsoft::String::destroy   [private]
 

Eliminates the contents of buffer and sets len to zero.

bool clawsoft::String::endsWith const char *    s
 

This method checks if the current string ends with the string stored in s.

bool clawsoft::String::endsWith String &    s
 

This method checks if the current string ends with the string stored in s.

bool clawsoft::String::equals const Sint64    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::equals const long double    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::equals const double    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::equals const float    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::equals const unsigned int    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::equals const int    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::equals const char *    s
 

Checks if the parameter s is equal to buffer.

bool clawsoft::String::equals const String &    s
 

Checks if the parameter s is equal to buffer.

bool clawsoft::String::equals const String &    s1,
const String &    s2
[static]
 

Checks if the parameter s1 is equal to s2.

int clawsoft::System::freeMemory   [static, inherited]
 

Will return the total amount of free system memory.

const char * clawsoft::Object::getClassName   [inherited]
 

Returns the name of the current class.

bool clawsoft::String::hasSubstring const char *    s
 

Tells if the substring s is inside the current String.

bool clawsoft::String::hasSubstring String &    s
 

Tells if the substring s is inside the current String.

const int clawsoft::String::index const char    c,
int    start = 0
 

Returns the leftmost position for string s inside buffer starting at byte start.

const int clawsoft::String::index const char *    s,
int    start = 0
 

Returns the leftmost position for string s inside buffer starting at byte start.

const int clawsoft::String::index String &    s,
int    start = 0
 

Returns the leftmost position for string s inside buffer starting at byte start.

String & clawsoft::String::insertCharAt const int    pos,
const char    c
 

Use this method when you need to add a given character c at position pos.

int clawsoft::System::installedCPUs   [static, inherited]
 

This will return how many CPUs are installed in the system.

const unsigned int clawsoft::String::lenght  
 

Returns the lenght of the string which is stored in len.

String & clawsoft::String::operator+ const Uint64    n
 

Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+ const Sint64    n
 

Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+ const long double    n
 

Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+ const double    n
 

Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+ const float    n
 

Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+ const unsigned int    n
 

Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+ const int    n
 

Transforms and concatenates n to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+ const char *    s
 

Concatenates s to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+ String &    s
 

Concatenates s to the current String by overriding the + operator returning an instance of itself.

String & clawsoft::String::operator+= const Uint64    n
 

Transforms n and concatenates it to the current String.

String & clawsoft::String::operator+= const Sint64    n
 

Transforms n and concatenates it to the current String.

String & clawsoft::String::operator+= const long double    n
 

Transforms n and concatenates it to the current String.

String & clawsoft::String::operator+= const double    n
 

Transforms n and concatenates it to the current String.

String & clawsoft::String::operator+= const float    n
 

Transforms n and concatenates it to the current String.

String & clawsoft::String::operator+= const unsigned int    n
 

Transforms n and concatenates it to the current String.

String & clawsoft::String::operator+= const int    n
 

Transforms n and concatenates it to the current String.

String & clawsoft::String::operator+= const char *    s
 

Concatenates s to itself.

String & clawsoft::String::operator+= String &    s
 

Concatenates s to itself.

String & clawsoft::String::operator= const Sint64    n
 

Transforms n and assigns it to buffer by calling assign(const char *);.

String & clawsoft::String::operator= const long double    n
 

Transforms n and assigns it to buffer by calling assign(const char *);.

String & clawsoft::String::operator= const double    n
 

Transforms n and assigns it to buffer by calling assign(const char *);.

String & clawsoft::String::operator= const float    n
 

Transforms n and assigns it to buffer by calling assign(const char *);.

String & clawsoft::String::operator= const unsigned int    n
 

Transforms n and assigns it to buffer by calling assign(const char *);.

String & clawsoft::String::operator= const int    n
 

Transforms n and assigns it to buffer by calling assign(const char *);.

String & clawsoft::String::operator= const char *    s
 

Assigns s to buffer by calling assign(const char *);.

bool clawsoft::String::operator== const Sint64    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::operator== const long double    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::operator== const double    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::operator== const float    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::operator== const unsigned int    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::operator== const int    n
 

Transforms and checks if the parameter n is equal to buffer.

bool clawsoft::String::operator== const char *    s
 

Checks if the parameter s is equal to buffer.

bool clawsoft::String::operator== const String &    s
 

Checks if the parameter s is equal to buffer.

const char clawsoft::String::operator[] int    i
 

Returns the character at position i by overriding the operator[].

const int clawsoft::String::rindex const char    c,
int    end = 0
 

Returns the rightmost position for string s inside buffer starting at byte end from right to left.

const int clawsoft::String::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 clawsoft::String::rindex String &    s,
int    end = 0
 

Returns the rightmost position for string s inside buffer starting at byte end from right to left.

void clawsoft::Object::setClassName const char *    n [protected, inherited]
 

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.

const unsigned int clawsoft::String::size  
 

Returns the lenght of the string which is stored in len.

bool clawsoft::String::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 clawsoft::String::startsWith const char *    s
 

This method checks if the current string starts with the string stored in s.

bool clawsoft::String::startsWith String &    s
 

This method checks if the current string starts with the string stored in s.

const char * clawsoft::String::toCharPtr  
 

returns a pointer to buffer

const double clawsoft::String::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 float clawsoft::String::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 int clawsoft::String::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 Sint64 clawsoft::String::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.

const long double clawsoft::String::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.

String & clawsoft::String::toLowerCase  
 

Transforms the string to lowercase letters only.

int clawsoft::System::totalMemory   [static, inherited]
 

Will return the total amount of system memory.

const unsigned int clawsoft::String::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.

String & clawsoft::String::toUpperCase  
 

Transforms the string to uppercase letters only.

String & clawsoft::String::trim const char    c = ' '
 

Eliminates all ocurrences of the c character that appears at the beginning and the end of the string.

String & clawsoft::String::trimLeft const char    c = ' '
 

Eliminates all ocurrences of the c character that appears at left of the string.

String & clawsoft::String::trimRight const char    c = ' '
 

Eliminates all ocurrences of the c character that appears at right of the string.

void clawsoft::System::usleep Uint32    usec [static, inherited]
 

Will freeze the software for usec microseconds.


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &    stream,
String    s
[friend]
 

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;.


Field Documentation

char* clawsoft::String::buffer [private]
 

Holds the string itself as and array of chars by default it points to null which also means empty String.

int clawsoft::String::len [private]
 

Holds the dimensions of the string plus one, the reserved address is for storing the termination character \0.


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

Authors:

Juan V. Guerrero
Jannette C. Mejia
Juan C. Guevara

Powered by:

SourceForgeLogo