Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 }