Logo
~Sockets~
~Examples~
~Contact~


cstring.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 #undef cstring
00024 #include "color.h"
00025 #include "cstring.h"
00026 
00027 // vs won't compile when I write out 'std::string' everywhere - blah
00028 using std::string;
00029 
00030 
00031 cstring::cstring()
00032 :string()
00033 ,m_cstr(NULL)
00034 ,m_ucstr(NULL)
00035 {
00036 }
00037 
00038 
00039 cstring::cstring(const std::string& p)
00040 :string(p)
00041 ,m_cstr(NULL)
00042 ,m_ucstr(NULL)
00043 {
00044 }
00045 
00046 
00047 cstring::~cstring()
00048 {
00049         if (m_cstr)
00050                 delete m_cstr;
00051         if (m_ucstr)
00052                 delete m_ucstr;
00053 }
00054 
00055 
00056 const char *cstring::c_str()
00057 {
00058         size_t n = size();
00059         std::string tmp;
00060 
00061         for (size_t i = 0; i < n; i++)
00062         {
00063                 if ((*this)[i] == '&')
00064                 {
00065                         i++;
00066                         switch ((*this)[i])
00067                         {
00068                         case 'n':
00069                                 tmp += CNRM;
00070                                 break;
00071                         case 'r':
00072                                 tmp += CRED;
00073                                 break;
00074                         case 'g':
00075                                 tmp += CGRN;
00076                                 break;
00077                         case 'y':
00078                                 tmp += CYEL;
00079                                 break;
00080                         case 'b':
00081                                 tmp += CBLU;
00082                                 break;
00083                         case 'm':
00084                                 tmp += CMAG;
00085                                 break;
00086                         case 'c':
00087                                 tmp += CCYN;
00088                                 break;
00089                         case 'w':
00090                                 tmp += CWHT;
00091                                 break;
00092                         case 'l':
00093                                 tmp += CBLK;
00094                                 break;
00095                         case 'R':
00096                                 tmp += BRED;
00097                                 break;
00098                         case 'G':
00099                                 tmp += BGRN;
00100                                 break;
00101                         case 'Y':
00102                                 tmp += BYEL;
00103                                 break;
00104                         case 'B':
00105                                 tmp += BBLU;
00106                                 break;
00107                         case 'M':
00108                                 tmp += BMAG;
00109                                 break;
00110                         case 'C':
00111                                 tmp += BCYN;
00112                                 break;
00113                         case 'W':
00114                                 tmp += BWHT;
00115                                 break;
00116                         case 'L':
00117                                 tmp += BBLK;
00118                                 break;
00119                         case 'e':
00120                                 tmp += BKRED;
00121                                 break;
00122                         case 'k':
00123                                 tmp += BKGRN;
00124                                 break;
00125                         case 'p':
00126                                 tmp += BKYEL;
00127                                 break;
00128                         case 'u':
00129                                 tmp += BKBLU;
00130                                 break;
00131                         case 'a':
00132                                 tmp += BKMAG;
00133                                 break;
00134                         case 'f':
00135                                 tmp += BKCYN;
00136                                 break;
00137                         case 'h':
00138                                 tmp += BKWHT;
00139                                 break;
00140                         case 'i':
00141                                 tmp += BKBLK;
00142                                 break;
00143                         case 'U':
00144                                 tmp += UNDER;
00145                                 break;
00146                         case 'F':
00147                                 tmp += FLASH;
00148                                 break;
00149                         case '&':
00150                                 tmp += (*this)[i];
00151                                 break;
00152                         default:
00153                                 i--;
00154                                 tmp += (*this)[i];
00155                                 break;
00156                         } // switch ((*this)[i])
00157                 }
00158                 else
00159                 if ((*this)[i] == '\n')
00160                 {
00161                         tmp += '\r';
00162                         tmp += (*this)[i];
00163                 }
00164                 else
00165                 {
00166                         tmp += (*this)[i];
00167                 }
00168         }
00169         if (m_cstr)
00170                 delete m_cstr;
00171         m_cstr = new char[tmp.size() + 1];
00172         memcpy(m_cstr,tmp.c_str(),tmp.size());
00173         m_cstr[tmp.size()] = 0;
00174 
00175         return m_cstr;
00176 }
00177 
00178 
00179 const char *cstring::uc_str()
00180 {
00181         size_t n = size();
00182         std::string tmp;
00183 
00184         for (size_t i = 0; i < n; i++)
00185         {
00186                 if ((*this)[i] == '&')
00187                 {
00188                         i++;
00189                         switch ((*this)[i])
00190                         {
00191                         case 'n':
00192                                 break;
00193                         case 'r':
00194                                 break;
00195                         case 'g':
00196                                 break;
00197                         case 'y':
00198                                 break;
00199                         case 'b':
00200                                 break;
00201                         case 'm':
00202                                 break;
00203                         case 'c':
00204                                 break;
00205                         case 'w':
00206                                 break;
00207                         case 'l':
00208                                 break;
00209                         case 'R':
00210                                 break;
00211                         case 'G':
00212                                 break;
00213                         case 'Y':
00214                                 break;
00215                         case 'B':
00216                                 break;
00217                         case 'M':
00218                                 break;
00219                         case 'C':
00220                                 break;
00221                         case 'W':
00222                                 break;
00223                         case 'L':
00224                                 break;
00225                         case 'e':
00226                                 break;
00227                         case 'k':
00228                                 break;
00229                         case 'p':
00230                                 break;
00231                         case 'u':
00232                                 break;
00233                         case 'a':
00234                                 break;
00235                         case 'f':
00236                                 break;
00237                         case 'h':
00238                                 break;
00239                         case 'i':
00240                                 break;
00241                         case 'U':
00242                                 break;
00243                         case 'F':
00244                                 break;
00245                         case '&':
00246                                 tmp += (*this)[i];
00247                                 break;
00248                         default:
00249                                 i--;
00250                                 tmp += (*this)[i];
00251                                 break;
00252                         } // switch ((*this)[i])
00253                 }
00254                 else
00255                 {
00256                         tmp += (*this)[i];
00257                 }
00258         }
00259         if (m_ucstr)
00260                 delete m_ucstr;
00261         m_ucstr = new char[tmp.size() + 1];
00262         memcpy(m_ucstr,tmp.c_str(),tmp.size());
00263         m_ucstr[tmp.size()] = 0;
00264 
00265         return m_ucstr;
00266 }
00267 
00268 
00269 bool cstring::operator==(const std::string& str)
00270 {
00271         return !strcmp(uc_str(),str.c_str());
00272 }
00273 
00274 
00275 bool cstring::operator==(cstring& str)
00276 {
00277         return !strcmp(uc_str(),str.uc_str());
00278 }
00279 
00280 
00281 bool cstring::operator==(const char *p)
00282 {
00283         return !strcmp(uc_str(),p);
00284 }
00285 
00286 
00287 //const cstring& 
00288 void cstring::operator=(const char *p)
00289 {
00290 //      return 
00291         string::operator=(p);
00292 }
00293 
00294 
00295 void cstring::operator+=(const char *p)
00296 {
00297         string::operator+=(p);
00298 }
00299 
00300 
00301 void cstring::operator+=(const std::string& p)
00302 {
00303         string::operator+=(p);
00304 }
00305 
00306 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4