00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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];
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::cat(const char *text)
00111 {
00112 char *cptr = txt;
00113 int len = strlen(txt) + strlen(text);
00114 txt = new char [len+1];
00115 ::strcpy(txt, cptr);
00116 ::strcat(txt, text);
00117 delete [] cptr;
00118 return len;
00119 }
00120
00121 char *rlString::strstr(const char *substring)
00122 {
00123 if(substring == NULL) return NULL;
00124 return ::strstr(txt,substring);
00125 }
00126
00127 int rlString::upper()
00128 {
00129 return ::rlupper(txt);
00130 }
00131
00132 int rlString::lower()
00133 {
00134 return ::rllower(txt);
00135 }
00136
00137 int rlString::startsWith(const char *startstr)
00138 {
00139 return ::rlStartsWith(txt,startstr);
00140 }
00141
00142 int rlString::strnocasecmp(const char *other)
00143 {
00144 rlString my,o;
00145 my.setText(txt);
00146 my.lower();
00147 o.setText(other);
00148 o.lower();
00149 return ::strcmp(my.text(),o.text());
00150 }
00151
00152 int rlString::strnnocasecmp(const char *other, int n)
00153 {
00154 rlString my,o;
00155 my.setText(txt);
00156 my.lower();
00157 o.setText(other);
00158 o.lower();
00159 return ::strncmp(my.text(),o.text(),n);
00160 }
00161
00162 char *rlString::strchr(int c)
00163 {
00164 return ::strchr(txt,c);
00165 }
00166
00167 char *rlString::strrchr(int c)
00168 {
00169 return ::strrchr(txt,c);
00170 }
00171