/*************************************************************************** str.cpp - description ------------------- begin : Tue Aug 1 2000 copyright : (C) 2000 by W. Baraldi & D. Scarpa email : baraldi@lacasilla.com.ar ***************************************************************************/ #include "str.h" #include const char Str::nul = '\0'; Str::Str(const char * string){ s=NULL; set(string); } Str::Str(Str * str){ s=NULL; if (str) set(str->s); } Str::~Str(){ if (s) delete[] s; } void Str::set(const char * string){ if (s) delete[] s; if (string){ s=new char[strlen(string)+1]; strcpy(s, string); }else s=NULL; } void Str::set(const Str * str){ set(((Str*)(str))->get()); } const char * Str::get(){ if (s) return (s); else return (&nul); } bool Str::contains(const char * string){ return (strstr(s, string)); } bool Str::contains(Str * str){ return (strstr(s, str->s)); } void Str::concat(const char * string){ char * aux=NULL; if (string){ aux=new char[strlen(s)+strlen(string)+1]; strcpy(aux, s), strcat(aux, string); free(s); } s=aux; } void Str::concat(Str * str){ concat(str->s); } int Str::lenght(){ return (strlen(s)); } bool Str::isEqual(Str * str, bool case_sensitive){ if (case_sensitive){ return (!strcmp(s, str->s)); } return (!strcasecmp(s, str->s)); } void Str::crop(unsigned int start, unsigned int end){ if (end>strlen(s)-1) end=strlen(s)-1; if (start