var::String Class Reference

Documentation

This is an embedded friendly string class. It is similar to the C++ string type but is built on Var::Data and cstring functions. The naming convetion follows that of std::string rather than the typical Stratify Library naming convention.

#include <stfy/Var.hpp>
String s1;
String s2;
s1 = "This is my string";
s1 << " " << s1.capacity() << "\n";
printf("%s", s1.c_str());
//Strings can be compared
s2 = "This is another string";
if( s1 == s2 ){
printf("The strings are the same!\n");
} else {
printf("The strings are different\n");
}

The above code outputs:

This is my string 64
The strings are different

Public Member Functions

void append (const char *a)
 
void append (char c)
 
void assign (const char *a, size_t subpos, size_t sublen)
 
void assign (const char *a, size_t n)
 
void assign (const char *a)
 
char at (size_t pos) const
 
float atoff () const
 
int atoi () const
 
int calc_delimited_data_size (char sep= ',', char term= '\n')
 
size_t copy (char *s, size_t len, size_t pos=0) const
 
bool empty () const
 
Stringerase (size_t pos, size_t len=-1)
 
size_t find (const String &str, size_t pos=0) const
 
size_t find (const char *str, size_t pos=0) const
 
size_t find (const char c, size_t pos=0) const
 
bool get_delimited_data (String &dest, int n, char sep= ',', char term= '\n')
 
Stringinsert (size_t pos, const char *s)
 
size_t length () const
 
bool operator!= (const char *cmp) const
 
Stringoperator= (const char *a)
 
Stringoperator= (String &a)
 
bool operator== (const char *cmp) const
 
void push_back (char c)
 
size_t size () const
 
 String ()
 
 String (size_t capacity)
 
 String (const char *s)
 
 String (const char *s, size_t len)
 
String substr (size_t pos=0, size_t len=npos) const
 
void tolower ()
 
void toupper ()
 
- Public Member Functions inherited from var::Data
int alloc (size_t size, bool resize=false)
 
virtual size_t calc_size () const
 
size_t capacity () const
 
char * cdata () const
 
const char * cdata_const () const
 
void clear ()
 
 Data ()
 
 Data (void *mem, size_t size, bool readonly=false)
 
 Data (size_t size)
 
void * data () const
 
const void * data_const () const
 
void fill (unsigned char d)
 
int free ()
 
int resize (size_t size)
 
void set (void *mem, size_t size, bool readonly=false)
 
int set_min_capacity (size_t s)
 
virtual ~Data ()
 

Additional Inherited Members

- Static Public Member Functions inherited from var::Data
static size_t min_size ()
 

Constructor & Destructor Documentation

var::String::String ( )

Declare an empty string

var::String::String ( size_t  capacity)

Declare an emtpy string of a specified capacity

var::String::String ( const char *  s)

Declare a string and initialize to s

var::String::String ( const char *  s,
size_t  len 
)

Declare a string and initialize to s

Member Function Documentation

void var::String::append ( const char *  a)

Append a (zero terminated) to string

void var::String::append ( char  c)

Append c to string

void var::String::assign ( const char *  a,
size_t  subpos,
size_t  sublen 
)
inline

Assign a substring of a to string

void var::String::assign ( const char *  a,
size_t  n 
)

Assign a maximum of n characters of a to string

void var::String::assign ( const char *  a)

Assign a (zero terminated) to string

char var::String::at ( size_t  pos) const

Return character at pos

float var::String::atoff ( ) const

Convert to a float

int var::String::atoi ( ) const
inline

Convert to an integer

int var::String::calc_delimited_data_size ( char  sep = ',',
char  term = '\n' 
)

Return the number of elements in the String

size_t var::String::copy ( char *  s,
size_t  len,
size_t  pos = 0 
) const

Copy a portion of the string to s

bool var::String::empty ( ) const
inline

Test if string is empty

String& var::String::erase ( size_t  pos,
size_t  len = -1 
)

Erase a portion of the string starting with the character at pos

size_t var::String::find ( const String str,
size_t  pos = 0 
) const

Find a var::String within the object

Parameters
strThe String to find
posThe position to start searching
Returns
The position of the string or var::String::npos if the String was not found
size_t var::String::find ( const char *  str,
size_t  pos = 0 
) const

Find a c string within the object

size_t var::String::find ( const char  c,
size_t  pos = 0 
) const

Find a character within the object

bool var::String::get_delimited_data ( String dest,
int  n,
char  sep = ',',
char  term = '\n' 
)

Copy the nth element (separated by sep) of the string to to dest

String& var::String::insert ( size_t  pos,
const char *  s 
)

Insert s (zero terminated) into string at pos

size_t var::String::length ( ) const
inline

Return the length of the string

bool var::String::operator!= ( const char *  cmp) const
inline

Compare to a c-string

String& var::String::operator= ( const char *  a)
inline

Assign a c-string

String& var::String::operator= ( String a)
inline

Assigns the value of a String to another String.

Parameters
aThe new String to assign
Returns
A reference to the destination String

This method will make a copy of the string in a new memory location rather than just using the data location of the source string.

bool var::String::operator== ( const char *  cmp) const
inline

Compare to a c-string

void var::String::push_back ( char  c)
inline

Append c to string

size_t var::String::size ( ) const
inline

Return the length of the string

String var::String::substr ( size_t  pos = 0,
size_t  len = npos 
) const

Get a sub string of the string

void var::String::tolower ( )

Convert to lower case

void var::String::toupper ( )

Convert to upper case