COSA
An Object-Oriented Platform for Arduino Programming
String Class Reference

#include <String.hh>

Inheritance diagram for String:
Inheritance graph
Collaboration diagram for String:
Collaboration graph

Public Member Functions

 String (const char *cstr="")
 
 String (const String &str)
 
 String (str_P str)
 
 String (char c)
 
 String (unsigned char, unsigned char base=10)
 
 String (int, unsigned char base=10)
 
 String (unsigned int, unsigned char base=10)
 
 String (long, unsigned char base=10)
 
 String (unsigned long, unsigned char base=10)
 
 String (float, unsigned char decimalPlaces=2)
 
 String (double, unsigned char decimalPlaces=2)
 
 ~String (void)
 
unsigned char reserve (unsigned int size)
 
unsigned int length (void) const
 
Stringoperator= (const String &rhs)
 
Stringoperator= (const char *cstr)
 
Stringoperator= (str_P str)
 
unsigned char concat (const String &str)
 
unsigned char concat (const char *cstr)
 
unsigned char concat (char c)
 
unsigned char concat (unsigned char c)
 
unsigned char concat (int num)
 
unsigned char concat (unsigned int num)
 
unsigned char concat (long num)
 
unsigned char concat (unsigned long num)
 
unsigned char concat (float num)
 
unsigned char concat (double num)
 
unsigned char concat (str_P str)
 
Stringoperator+= (const String &rhs)
 
Stringoperator+= (const char *cstr)
 
Stringoperator+= (char c)
 
Stringoperator+= (unsigned char num)
 
Stringoperator+= (int num)
 
Stringoperator+= (unsigned int num)
 
Stringoperator+= (long num)
 
Stringoperator+= (unsigned long num)
 
Stringoperator+= (float num)
 
Stringoperator+= (double num)
 
Stringoperator+= (str_P str)
 
 operator StringIfHelperType () const
 
int compareTo (const String &s) const
 
unsigned char equals (const String &s) const
 
unsigned char equals (const char *cstr) const
 
unsigned char operator== (const String &rhs) const
 
unsigned char operator== (const char *cstr) const
 
unsigned char operator!= (const String &rhs) const
 
unsigned char operator!= (const char *cstr) const
 
unsigned char operator< (const String &rhs) const
 
unsigned char operator> (const String &rhs) const
 
unsigned char operator<= (const String &rhs) const
 
unsigned char operator>= (const String &rhs) const
 
unsigned char equalsIgnoreCase (const String &s) const
 
unsigned char startsWith (const String &prefix) const
 
unsigned char startsWith (const String &prefix, unsigned int offset) const
 
unsigned char endsWith (const String &suffix) const
 
char charAt (unsigned int index) const
 
void setCharAt (unsigned int index, char c)
 
char operator[] (unsigned int index) const
 
char & operator[] (unsigned int index)
 
void getBytes (unsigned char *buf, unsigned int bufsize, unsigned int index=0) const
 
void toCharArray (char *buf, unsigned int bufsize, unsigned int index=0) const
 
const char * c_str () const
 
int indexOf (char ch) const
 
int indexOf (char ch, unsigned int fromIndex) const
 
int indexOf (const String &str) const
 
int indexOf (const String &str, unsigned int fromIndex) const
 
int lastIndexOf (char ch) const
 
int lastIndexOf (char ch, unsigned int fromIndex) const
 
int lastIndexOf (const String &str) const
 
int lastIndexOf (const String &str, unsigned int fromIndex) const
 
String substring (unsigned int beginIndex, unsigned int endIndex) const
 
String substring (unsigned int beginIndex) const
 
void replace (char find, char replace)
 
void replace (const String &find, const String &replace)
 
void remove (unsigned int index)
 
void remove (unsigned int index, unsigned int count)
 
void toLowerCase (void)
 
void toUpperCase (void)
 
void trim (void)
 
long toInt (void) const
 
float toFloat (void) const
 

Protected Member Functions

void init (void)
 
void invalidate (void)
 
unsigned char changeBuffer (unsigned int maxStrLen)
 
unsigned char concat (const char *cstr, unsigned int length)
 
Stringcopy (const char *cstr, unsigned int length)
 
Stringcopy (str_P pstr, unsigned int length)
 
void move (String &rhs)
 

Protected Attributes

char * m_buffer
 the actual char array More...
 
unsigned int m_capacity
 the array length minus one (for the '\0') More...
 
unsigned int m_length
 the String length (not counting the '\0') More...
 

Friends

__StringSumHelperoperator+ (const __StringSumHelper &lhs, const String &rhs)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, const char *cstr)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, char c)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, unsigned char num)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, int num)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, unsigned int num)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, long num)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, unsigned long num)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, float num)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, double num)
 
__StringSumHelperoperator+ (const __StringSumHelper &lhs, str_P rhs)
 

Detailed Description

The String class; dynamic, resizable strings.

Definition at line 37 of file String.hh.

Constructor & Destructor Documentation

String::String ( const char *  cstr = "")

Creates a copy of the initial value. If the initial value is null or invalid, or if memory allocation fails, the string will be marked as invalid (i.e. "if (s)" will be false).

Definition at line 26 of file String.cpp.

String::String ( const String str)

Definition at line 32 of file String.cpp.

String::String ( str_P  str)

Definition at line 38 of file String.cpp.

String::String ( char  c)
explicit

Definition at line 58 of file String.cpp.

String::String ( unsigned char  value,
unsigned char  base = 10 
)
explicit

Definition at line 67 of file String.cpp.

String::String ( int  value,
unsigned char  base = 10 
)
explicit

Definition at line 75 of file String.cpp.

String::String ( unsigned int  value,
unsigned char  base = 10 
)
explicit

Definition at line 83 of file String.cpp.

String::String ( long  value,
unsigned char  base = 10 
)
explicit

Definition at line 91 of file String.cpp.

String::String ( unsigned long  value,
unsigned char  base = 10 
)
explicit

Definition at line 99 of file String.cpp.

String::String ( float  value,
unsigned char  decimalPlaces = 2 
)
explicit

Definition at line 107 of file String.cpp.

String::String ( double  value,
unsigned char  decimalPlaces = 2 
)
explicit

Definition at line 114 of file String.cpp.

String::~String ( void  )

Definition at line 121 of file String.cpp.

Member Function Documentation

const char* String::c_str ( ) const
inline

Definition at line 186 of file String.hh.

unsigned char String::changeBuffer ( unsigned int  maxStrLen)
protected

Definition at line 153 of file String.cpp.

char String::charAt ( unsigned int  index) const

Character acccess.

Definition at line 535 of file String.cpp.

int String::compareTo ( const String s) const

Definition at line 443 of file String.cpp.

unsigned char String::concat ( const String str)

Concatenate value. Returns true on success, false on failure (in which case, the string is left unchanged). If the argument is null or invalid, the concatenation is considered unsucessful.

Definition at line 252 of file String.cpp.

unsigned char String::concat ( const char *  cstr)

Definition at line 270 of file String.cpp.

unsigned char String::concat ( char  c)

Definition at line 277 of file String.cpp.

unsigned char String::concat ( unsigned char  c)

Definition at line 286 of file String.cpp.

unsigned char String::concat ( int  num)

Definition at line 294 of file String.cpp.

unsigned char String::concat ( unsigned int  num)

Definition at line 302 of file String.cpp.

unsigned char String::concat ( long  num)

Definition at line 310 of file String.cpp.

unsigned char String::concat ( unsigned long  num)

Definition at line 318 of file String.cpp.

unsigned char String::concat ( float  num)

Definition at line 326 of file String.cpp.

unsigned char String::concat ( double  num)

Definition at line 334 of file String.cpp.

unsigned char String::concat ( str_P  str)

Definition at line 342 of file String.cpp.

unsigned char String::concat ( const char *  cstr,
unsigned int  length 
)
protected

Definition at line 258 of file String.cpp.

String & String::copy ( const char *  cstr,
unsigned int  length 
)
protected

Copy and move.

Definition at line 163 of file String.cpp.

String & String::copy ( str_P  pstr,
unsigned int  length 
)
protected

Definition at line 176 of file String.cpp.

unsigned char String::endsWith ( const String suffix) const

Definition at line 526 of file String.cpp.

unsigned char String::equals ( const String s) const

Definition at line 456 of file String.cpp.

unsigned char String::equals ( const char *  cstr) const

Definition at line 462 of file String.cpp.

unsigned char String::equalsIgnoreCase ( const String s) const

Definition at line 496 of file String.cpp.

void String::getBytes ( unsigned char *  buf,
unsigned int  bufsize,
unsigned int  index = 0 
) const

Definition at line 565 of file String.cpp.

int String::indexOf ( char  ch) const

Search.

Definition at line 579 of file String.cpp.

int String::indexOf ( char  ch,
unsigned int  fromIndex 
) const

Definition at line 585 of file String.cpp.

int String::indexOf ( const String str) const

Definition at line 594 of file String.cpp.

int String::indexOf ( const String str,
unsigned int  fromIndex 
) const

Definition at line 600 of file String.cpp.

void String::init ( void  )
inlineprotected

Definition at line 127 of file String.cpp.

void String::invalidate ( void  )
protected

Definition at line 135 of file String.cpp.

int String::lastIndexOf ( char  ch) const

Definition at line 609 of file String.cpp.

int String::lastIndexOf ( char  ch,
unsigned int  fromIndex 
) const

Definition at line 615 of file String.cpp.

int String::lastIndexOf ( const String str) const

Definition at line 627 of file String.cpp.

int String::lastIndexOf ( const String str,
unsigned int  fromIndex 
) const

Definition at line 633 of file String.cpp.

unsigned int String::length ( void  ) const
inline

Return string length.

Definition at line 83 of file String.hh.

void String::move ( String rhs)
protected

Definition at line 188 of file String.cpp.

String::operator StringIfHelperType ( ) const
inline

Comparison (only works w/ Strings and "strings").

Definition at line 151 of file String.hh.

unsigned char String::operator!= ( const String rhs) const
inline

Definition at line 161 of file String.hh.

unsigned char String::operator!= ( const char *  cstr) const
inline

Definition at line 162 of file String.hh.

String& String::operator+= ( const String rhs)
inline

If there's not enough memory for the concatenated value, the string will be left unchanged (but this isn't signalled in any way)

Definition at line 124 of file String.hh.

String& String::operator+= ( const char *  cstr)
inline

Definition at line 125 of file String.hh.

String& String::operator+= ( char  c)
inline

Definition at line 126 of file String.hh.

String& String::operator+= ( unsigned char  num)
inline

Definition at line 127 of file String.hh.

String& String::operator+= ( int  num)
inline

Definition at line 128 of file String.hh.

String& String::operator+= ( unsigned int  num)
inline

Definition at line 129 of file String.hh.

String& String::operator+= ( long  num)
inline

Definition at line 130 of file String.hh.

String& String::operator+= ( unsigned long  num)
inline

Definition at line 131 of file String.hh.

String& String::operator+= ( float  num)
inline

Definition at line 132 of file String.hh.

String& String::operator+= ( double  num)
inline

Definition at line 133 of file String.hh.

String& String::operator+= ( str_P  str)
inline

Definition at line 134 of file String.hh.

unsigned char String::operator< ( const String rhs) const

Definition at line 472 of file String.cpp.

unsigned char String::operator<= ( const String rhs) const

Definition at line 484 of file String.cpp.

String & String::operator= ( const String rhs)

Creates a copy of the assigned value. if the value is null or invalid, or if the memory allocation fails, the string will be marked as invalid ("if (s)" will be false).

Definition at line 209 of file String.cpp.

String & String::operator= ( const char *  cstr)

Definition at line 236 of file String.cpp.

String & String::operator= ( str_P  str)

Definition at line 244 of file String.cpp.

unsigned char String::operator== ( const String rhs) const
inline

Definition at line 159 of file String.hh.

unsigned char String::operator== ( const char *  cstr) const
inline

Definition at line 160 of file String.hh.

unsigned char String::operator> ( const String rhs) const

Definition at line 478 of file String.cpp.

unsigned char String::operator>= ( const String rhs) const

Definition at line 490 of file String.cpp.

char String::operator[] ( unsigned int  index) const

Definition at line 558 of file String.cpp.

char & String::operator[] ( unsigned int  index)

Definition at line 547 of file String.cpp.

void String::remove ( unsigned int  index)

Definition at line 720 of file String.cpp.

void String::remove ( unsigned int  index,
unsigned int  count 
)

Definition at line 727 of file String.cpp.

void String::replace ( char  find,
char  replace 
)

Modification.

Definition at line 667 of file String.cpp.

void String::replace ( const String find,
const String replace 
)

Definition at line 676 of file String.cpp.

unsigned char String::reserve ( unsigned int  size)

Memory Management: Return true on success, false on failure (in which case, the string is left unchanged). reserve(0), if successful, will validate an invalid string (i.e., "if (s)" will be true afterwards)

Definition at line 144 of file String.cpp.

void String::setCharAt ( unsigned int  index,
char  c 
)

Definition at line 541 of file String.cpp.

unsigned char String::startsWith ( const String prefix) const

Definition at line 510 of file String.cpp.

unsigned char String::startsWith ( const String prefix,
unsigned int  offset 
) const

Definition at line 517 of file String.cpp.

String String::substring ( unsigned int  beginIndex,
unsigned int  endIndex 
) const

Sub-string.

Definition at line 649 of file String.cpp.

String String::substring ( unsigned int  beginIndex) const
inline

Definition at line 204 of file String.hh.

void String::toCharArray ( char *  buf,
unsigned int  bufsize,
unsigned int  index = 0 
) const
inline

Definition at line 181 of file String.hh.

float String::toFloat ( void  ) const

Definition at line 777 of file String.cpp.

long String::toInt ( void  ) const

Parsing/Conversion.

Definition at line 770 of file String.cpp.

void String::toLowerCase ( void  )

Definition at line 739 of file String.cpp.

void String::toUpperCase ( void  )

Definition at line 748 of file String.cpp.

void String::trim ( void  )

Definition at line 757 of file String.cpp.

Friends And Related Function Documentation

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
const String rhs 
)
friend

Definition at line 355 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
const char *  cstr 
)
friend

Definition at line 363 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
char  c 
)
friend

Definition at line 371 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
unsigned char  num 
)
friend

Definition at line 379 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
int  num 
)
friend

Definition at line 387 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
unsigned int  num 
)
friend

Definition at line 395 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
long  num 
)
friend

Definition at line 403 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
unsigned long  num 
)
friend

Definition at line 411 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
float  num 
)
friend

Definition at line 419 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
double  num 
)
friend

Definition at line 427 of file String.cpp.

__StringSumHelper& operator+ ( const __StringSumHelper lhs,
str_P  rhs 
)
friend

Definition at line 435 of file String.cpp.

Member Data Documentation

char* String::m_buffer
protected

the actual char array

Definition at line 227 of file String.hh.

unsigned int String::m_capacity
protected

the array length minus one (for the '\0')

Definition at line 228 of file String.hh.

unsigned int String::m_length
protected

the String length (not counting the '\0')

Definition at line 229 of file String.hh.


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