rllib  1
Public Member Functions | Private Attributes
rlString Class Reference

#include <rlstring.h>

List of all members.

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)
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];
  ::strcpy(txt, text);
}
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 120 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 142 of file rlstring.cpp.

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::printf ( const char *  format,
  ... 
)
  printf the text
  

Definition at line 94 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 182 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 85 of file rlstring.cpp.

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

Definition at line 147 of file rlstring.cpp.

{
  return ::rlStartsWith(txt,startstr);
}
char * rlString::strchr ( int  c)
  strchr()
  

Definition at line 172 of file rlstring.cpp.

int rlString::strcpy ( const char *  text)
  copy text
  

Definition at line 110 of file rlstring.cpp.

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

Definition at line 162 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 152 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 177 of file rlstring.cpp.

char * rlString::strstr ( const char *  substring)
  strstr()
  

Definition at line 131 of file rlstring.cpp.

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

Definition at line 80 of file rlstring.cpp.

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

Definition at line 137 of file rlstring.cpp.


Member Data Documentation

char* rlString::txt [private]

Definition at line 121 of file rlstring.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines