|
rllib
1
|
00001 /*************************************************************************** 00002 rlmailbox.cpp - description 00003 ------------------- 00004 begin : Wed Jan 02 2008 00005 copyright : (C) Lehrig Software Enigineering 00006 email : lehrig@t-online.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This library is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as * 00013 * published by the Free Software Foundation * 00014 * * 00015 ***************************************************************************/ 00016 00017 #include <stdarg.h> 00018 #include "rlstring.h" 00019 #include "rlcutil.h" 00020 00021 rlString::rlString(const char *text) 00022 { 00023 txt = new char [strlen(text)+1]; 00024 ::strcpy(txt, text); 00025 } 00026 00027 rlString::rlString(rlString &s2) 00028 { 00029 txt = new char [strlen(s2.text())+1]; 00030 ::strcpy(txt,s2.text()); 00031 } 00032 00033 rlString::rlString(rlString *s2) 00034 { 00035 txt = new char [strlen(s2->text())+1]; 00036 ::strcpy(txt,s2->text()); 00037 } 00038 00039 rlString::~rlString() 00040 { 00041 delete [] txt; 00042 } 00043 00044 rlString& rlString::operator=(const char *s2) 00045 { 00046 this->setText(s2); 00047 return *this; 00048 } 00049 00050 rlString& rlString::operator=(rlString &s2) 00051 { 00052 this->setText(s2.text()); 00053 return *this; 00054 } 00055 00056 rlString& rlString::operator+(const char *s2) 00057 { 00058 this->cat(s2); 00059 return *this; 00060 } 00061 00062 rlString& rlString::operator+(rlString &s2) 00063 { 00064 this->cat(s2.text()); 00065 return *this; 00066 } 00067 00068 rlString& rlString::operator+=(const char *s2) 00069 { 00070 this->cat(s2); 00071 return *this; 00072 } 00073 00074 rlString& rlString::operator+=(rlString &s2) 00075 { 00076 this->cat(s2.text()); 00077 return *this; 00078 } 00079 00080 char * rlString::text() 00081 { 00082 return txt; 00083 } 00084 00085 int rlString::setText(const char *text) 00086 { 00087 int ret = strlen(text); 00088 delete [] txt; 00089 txt = new char [ret+1]; 00090 ::strcpy(txt, text); 00091 return ret; 00092 } 00093 00094 int rlString::printf(const char *format, ...) 00095 { 00096 int ret; 00097 char mystring[rl_PRINTF_LENGTH]; // should be big enough 00098 00099 va_list ap; 00100 va_start(ap,format); 00101 ret = rlvsnprintf(mystring, rl_PRINTF_LENGTH - 1, format, ap); 00102 va_end(ap); 00103 if(ret < 0) return ret; 00104 delete [] txt; 00105 txt = new char [strlen(mystring)+1]; 00106 ::strcpy(txt, mystring); 00107 return ret; 00108 } 00109 00110 int rlString::strcpy(const char *text) 00111 { 00112 char *cptr = txt; 00113 int len = strlen(text); 00114 txt = new char [len+1]; 00115 ::strcpy(txt, text); 00116 delete [] cptr; 00117 return len; 00118 } 00119 00120 int rlString::cat(const char *text) 00121 { 00122 char *cptr = txt; 00123 int len = strlen(txt) + strlen(text); 00124 txt = new char [len+1]; 00125 ::strcpy(txt, cptr); 00126 ::strcat(txt, text); 00127 delete [] cptr; 00128 return len; 00129 } 00130 00131 char *rlString::strstr(const char *substring) 00132 { 00133 if(substring == NULL) return NULL; 00134 return ::strstr(txt,substring); 00135 } 00136 00137 int rlString::upper() 00138 { 00139 return ::rlupper(txt); 00140 } 00141 00142 int rlString::lower() 00143 { 00144 return ::rllower(txt); 00145 } 00146 00147 int rlString::startsWith(const char *startstr) 00148 { 00149 return ::rlStartsWith(txt,startstr); 00150 } 00151 00152 int rlString::strnocasecmp(const char *other) 00153 { 00154 rlString my,o; 00155 my.setText(txt); 00156 my.lower(); 00157 o.setText(other); 00158 o.lower(); 00159 return ::strcmp(my.text(),o.text()); 00160 } 00161 00162 int rlString::strnnocasecmp(const char *other, int n) 00163 { 00164 rlString my,o; 00165 my.setText(txt); 00166 my.lower(); 00167 o.setText(other); 00168 o.lower(); 00169 return ::strncmp(my.text(),o.text(),n); 00170 } 00171 00172 char *rlString::strchr(int c) 00173 { 00174 return ::strchr(txt,c); 00175 } 00176 00177 char *rlString::strrchr(int c) 00178 { 00179 return ::strrchr(txt,c); 00180 } 00181 00182 int rlString::removeQuotas(char q) 00183 { 00184 char c; 00185 int state=0, inquotas=0, j=0; 00186 int len = strlen(txt); 00187 00188 for(int i=0;i<len;i++) 00189 { 00190 c = txt[i]; 00191 switch(state) 00192 { 00193 case 0: //START 00194 if(c==q) 00195 { 00196 state=1; 00197 inquotas=1; 00198 break; 00199 } 00200 state=1; 00201 case 1: // BODY 00202 if(inquotas==1) 00203 { 00204 if(c==q) 00205 { 00206 inquotas=0; 00207 break; 00208 } 00209 } 00210 txt[j++]=c; 00211 break; 00212 default: 00213 break; 00214 } 00215 } 00216 txt[j++]=0; 00217 return j; 00218 } 00219
1.7.5.1