rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Private Attributes | List of all members
rlString Class Reference

#include <rlstring.h>

Public Member Functions

 rlString (const char *text="")
 
 rlString (rlString &text)
 
 rlString (rlString *text)
 
virtual ~rlString ()
 
rlStringoperator= (const char *s2)
 
rlStringoperator= (rlString &s2)
 
rlStringoperator+ (const char *s2)
 
rlStringoperator+ (rlString &s2)
 
rlStringoperator+= (const char *s2)
 
rlStringoperator+= (rlString &s2)
 
int operator== (const char *s2)
 
int operator== (rlString &s2)
 
int operator!= (const char *s2)
 
int operator!= (rlString &s2)
 
char * text ()
 
int setText (const char *text)
 
int printf (const char *format,...)
 
int strcpy (const char *text)
 
int cat (const char *text)
 
int upper ()
 
int lower ()
 
int startsWith (const char *startstr)
 
int strnocasecmp (const char *other)
 
int strnnocasecmp (const char *other, int n)
 
char * strstr (const char *substring)
 
char * strchr (int c)
 
char * strrchr (int c)
 
int removeQuotas (char c='"')
 

Private Attributes

char * txt
 

Detailed Description

class for a simple ANSI-C like string.

Definition at line 25 of file rlstring.h.

Constructor & Destructor Documentation

rlString::rlString ( const char *  text = "")
 construct the string
 

Definition at line 21 of file rlstring.cpp.

{
txt = new char [strlen(text)+1];
}
rlString::rlString ( rlString text)

Definition at line 27 of file rlstring.cpp.

{
txt = new char [strlen(s2.text())+1];
::strcpy(txt,s2.text());
}
rlString::rlString ( rlString text)

Definition at line 33 of file rlstring.cpp.

{
txt = new char [strlen(s2->text())+1];
::strcpy(txt,s2->text());
}
rlString::~rlString ( )
virtual
 destruct the string
 

Definition at line 39 of file rlstring.cpp.

{
delete [] txt;
}

Member Function Documentation

int rlString::cat ( const char *  text)
 append text
 

Definition at line 144 of file rlstring.cpp.

{
char *cptr = txt;
int len = strlen(txt) + strlen(text);
txt = new char [len+1];
::strcpy(txt, cptr);
::strcat(txt, text);
delete [] cptr;
return len;
}
int rlString::lower ( )
 converst string to upper case
 

Definition at line 166 of file rlstring.cpp.

int rlString::operator!= ( const char *  s2)

Definition at line 92 of file rlstring.cpp.

{
if(strcmp(txt,s2) != 0) return 1;
return 0;
}
int rlString::operator!= ( rlString s2)

Definition at line 98 of file rlstring.cpp.

{
if(strcmp(txt,s2.text()) != 0) return 1;
return 0;
}
rlString & rlString::operator+ ( const char *  s2)

Definition at line 56 of file rlstring.cpp.

{
this->cat(s2);
return *this;
}
rlString & rlString::operator+ ( rlString s2)

Definition at line 62 of file rlstring.cpp.

{
this->cat(s2.text());
return *this;
}
rlString & rlString::operator+= ( const char *  s2)

Definition at line 68 of file rlstring.cpp.

{
this->cat(s2);
return *this;
}
rlString & rlString::operator+= ( rlString s2)

Definition at line 74 of file rlstring.cpp.

{
this->cat(s2.text());
return *this;
}
rlString & rlString::operator= ( const char *  s2)

Definition at line 44 of file rlstring.cpp.

{
this->setText(s2);
return *this;
}
rlString & rlString::operator= ( rlString s2)

Definition at line 50 of file rlstring.cpp.

{
this->setText(s2.text());
return *this;
}
int rlString::operator== ( const char *  s2)

Definition at line 80 of file rlstring.cpp.

{
if(strcmp(txt,s2) == 0) return 1;
return 0;
}
int rlString::operator== ( rlString s2)

Definition at line 86 of file rlstring.cpp.

{
if(strcmp(txt,s2.text()) == 0) return 1;
return 0;
}
int rlString::printf ( const char *  format,
  ... 
)
 printf the text
 

Definition at line 118 of file rlstring.cpp.

{
int ret;
char mystring[rl_PRINTF_LENGTH]; // should be big enough
va_list ap;
va_start(ap,format);
ret = rlvsnprintf(mystring, rl_PRINTF_LENGTH - 1, format, ap);
va_end(ap);
if(ret < 0) return ret;
delete [] txt;
txt = new char [strlen(mystring)+1];
::strcpy(txt, mystring);
return ret;
}
int rlString::removeQuotas ( char  c = '"')
 Remove quotas around a string.
 This might be usefull together with CSV files.
 

Definition at line 206 of file rlstring.cpp.

{
char c;
int state=0, inquotas=0, j=0;
int len = strlen(txt);
for(int i=0;i<len;i++)
{
c = txt[i];
switch(state)
{
case 0: //START
if(c==q)
{
state=1;
inquotas=1;
break;
}
state=1;
case 1: // BODY
if(inquotas==1)
{
if(c==q)
{
inquotas=0;
break;
}
}
txt[j++]=c;
break;
default:
break;
}
}
txt[j++]=0;
return j;
}
int rlString::setText ( const char *  text)
 set the text
 

Definition at line 109 of file rlstring.cpp.

{
int ret = strlen(text);
delete [] txt;
txt = new char [ret+1];
return ret;
}
int rlString::startsWith ( const char *  startstr)
 test if string starts with startstr
 

Definition at line 171 of file rlstring.cpp.

{
}
char * rlString::strchr ( int  c)
 strchr()
 

Definition at line 196 of file rlstring.cpp.

{
return ::strchr(txt,c);
}
int rlString::strcpy ( const char *  text)
 copy text
 

Definition at line 134 of file rlstring.cpp.

{
char *cptr = txt;
int len = strlen(text);
txt = new char [len+1];
delete [] cptr;
return len;
}
int rlString::strnnocasecmp ( const char *  other,
int  n 
)
 case insensitive string compare starting n characters
 

Definition at line 186 of file rlstring.cpp.

{
rlString my,o;
my.setText(txt);
my.lower();
o.setText(other);
o.lower();
return ::strncmp(my.text(),o.text(),n);
}
int rlString::strnocasecmp ( const char *  other)
 case insensitive string compare
 

Definition at line 176 of file rlstring.cpp.

{
rlString my,o;
my.setText(txt);
my.lower();
o.setText(other);
o.lower();
return ::strcmp(my.text(),o.text());
}
char * rlString::strrchr ( int  c)
 strchr()
 

Definition at line 201 of file rlstring.cpp.

{
return ::strrchr(txt,c);
}
char * rlString::strstr ( const char *  substring)
 strstr()
 

Definition at line 155 of file rlstring.cpp.

{
if(substring == NULL) return NULL;
return ::strstr(txt,substring);
}
char * rlString::text ( )
 get the text
 

Definition at line 104 of file rlstring.cpp.

{
return txt;
}
int rlString::upper ( )
 converst string to upper case
 

Definition at line 161 of file rlstring.cpp.

Member Data Documentation

char* rlString::txt
private

Definition at line 127 of file rlstring.h.


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