• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/DcString.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net)
00003 This file is part of Beesnest.
00004 
00005 Beesnest is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 Beesnest is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with Beesnest; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 
00021 /**
00022  * CdcString.cpp: implementation of the CdcString class.
00023  * for documentation see the header file.
00024  */
00025 
00026 #include "DcString.h"
00027 
00028 int CdcString::CompareNoCase (const CdcString& str) const
00029 {
00030     CdcString temp1 = *this;
00031     CdcString temp2 = str;
00032 
00033     temp1.MakeLower ();
00034     temp2.MakeLower ();
00035 
00036     return temp1.Compare (temp2);
00037 }
00038 
00039 int CdcString::CompareEnd (const CdcString& str) const
00040 {
00041     int i = this->GetLength () - 1;
00042     int j = str.GetLength () - 1;
00043     int cmp;
00044     while (i >= 0 && j >= 0)
00045     {
00046         cmp = (*this)[i--] - str[j--];
00047         if (cmp != 0) return cmp;
00048     }
00049     return 0;
00050 }
00051 
00052 void CdcString::MakeUpper ()
00053 {
00054     for (string::iterator iter = this->begin();
00055         iter != this->end(); iter++)
00056     {
00057         if (*iter >= 'a' && *iter <= 'z')
00058             *iter -= 32;
00059     }
00060 }
00061 
00062 
00063 void CdcString::MakeLower ()
00064 {
00065     for (string::iterator iter = this->begin();
00066         iter != this->end(); iter++)
00067     {
00068         if (*iter >= 'A' && *iter <= 'Z')
00069             *iter += 32;
00070     }
00071 }
00072 
00073 
00074 
00075 void CdcString::Replace (const CdcString& strOld, const CdcString& strNew)
00076 {
00077     int place = -1;
00078     while ((place = Find (strOld, place + 1)) != string::npos)
00079         replace (place, strOld.GetLength (), strNew);
00080 }
00081 
00082 
00083 void CdcString::TrimLeft ()
00084 {
00085     int count = 0;
00086     for (string::iterator iter = this->begin();
00087         iter != this->end(); iter++)
00088     {
00089         if (isspace (*iter))
00090             ++ count;
00091         else
00092             break;
00093     }
00094 
00095     *this = this->erase (0, count);
00096 }
00097 
00098 void CdcString::TrimRight ()
00099 {
00100     int count = 0;
00101     for (string::reverse_iterator iter = this->rbegin();
00102         iter != this->rend(); iter++)
00103     {
00104         if (isspace (*iter))
00105             ++ count;
00106         else
00107             break;
00108     }
00109 
00110     *this = this->erase (GetLength () - count, count);
00111 }
00112 
00113 
00114 CdcString CdcString::SpanIncluding (const CdcString& charSet) const
00115 {
00116     int count = 0;
00117     for (string::const_iterator iter = this->begin();
00118         iter != this->end(); iter++)
00119     {
00120         if (charSet.Find (*iter) != string::npos)
00121             ++ count;
00122         else
00123             break;
00124     }
00125 
00126     return Left (count);
00127 }
00128 
00129 
00130 CdcString CdcString::IntToString (int num, const char* format)
00131 {
00132     char buff [40];
00133     sprintf (buff, format, num);
00134     return buff;
00135 }

Generated on Mon Oct 11 2010 16:23:24 for Beesnest by  doxygen 1.7.2