(file) Return to String.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/String.cpp between version 1.2 and 1.7

version 1.2, 2001/02/11 05:42:33 version 1.7, 2001/04/10 22:42:55
Line 23 
Line 23 
 // Author: // Author:
 // //
 // $Log$ // $Log$
   // Revision 1.7  2001/04/10 22:42:55  karl
   // Correct error in String find
   //
   // Revision 1.6  2001/04/09 20:18:47  karl
   // add find substring function
   //
   // Revision 1.5  2001/03/09 19:49:32  karl
   // long lines
   //
   // Revision 1.4  2001/02/26 04:33:28  mike
   // Fixed many places where cim names compared with operator==(String,String).
   // Changed all of these to use CIMName::equal()
   //
   // Revision 1.3  2001/02/11 17:19:30  mike
   // added reverseFind() method
   //
 // Revision 1.2  2001/02/11 05:42:33  mike // Revision 1.2  2001/02/11 05:42:33  mike
 // new // new
 // //
Line 32 
Line 48 
 // //
 //END_HISTORY //END_HISTORY
  
   
 #include <cctype> #include <cctype>
 #include "String.h" #include "String.h"
 #include "Exception.h" #include "Exception.h"
 #include "String.h" #include "String.h"
  
   // For debugging
   #include <iostream>
   using namespace std;
   
   
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 const String String::EMPTY; const String String::EMPTY;
Line 235 
Line 257 
         _rep.remove(pos, size);         _rep.remove(pos, size);
 } }
  
 Boolean operator==(const String& x, const String& y)  int String::compare(const Char16* s1, const Char16* s2, Uint32 n)
   {
       while (n--)
       {
           int r = *s1++ - *s2++;
   
           if (r)
               return r;
       }
   
       return 0;
   }
   
   Boolean String::equal(const String& x, const String& y)
 { {
     if (x.getLength() != y.getLength())     if (x.getLength() != y.getLength())
         return false;         return false;
Line 243 
Line 278 
     return String::compare(x.getData(), y.getData(), x.getLength()) == 0;     return String::compare(x.getData(), y.getData(), x.getLength()) == 0;
 } }
  
 Boolean operator==(const String& x, const Char16* y)  Boolean String::equal(const String& x, const Char16* y)
 { {
     if (x.getLength() != StrLen(y))     if (x.getLength() != StrLen(y))
         return false;         return false;
Line 251 
Line 286 
     return String::compare(x.getData(), y, x.getLength()) == 0;     return String::compare(x.getData(), y, x.getLength()) == 0;
 } }
  
 inline Boolean operator==(const Char16* x, const String& y)  Boolean String::equal(const Char16* x, const String& y)
 { {
     return operator==(y, x);      return equal(y, x);
 } }
  
 int String::compare(const Char16* s1, const Char16* s2, Uint32 n)  Boolean String::equal(const String& x, const char* y)
 {  
     while (n--)  
     {     {
         int r = *s1++ - *s2++;      return equal(x, String(y));
   
         if (r)  
             return r;  
     }     }
  
     return 0;  Boolean String::equal(const char* x, const String& y)
   {
       return equal(String(x), y);
 } }
  
   
 String String::subString(Uint32 pos, Uint32 length) const String String::subString(Uint32 pos, Uint32 length) const
 { {
     if (pos < getLength())     if (pos < getLength())
Line 295 
Line 328 
     return Uint32(-1);     return Uint32(-1);
 } }
  
   Uint32 String::find(const String& s) const
   {
       const Char16* pSubStr = s.getData();
       const Char16* pStr = getData();
       Uint32 subStrLen = s.getLength();
       Uint32 strLen = getLength();
   
       // loop to find first char match
       Uint32 loc = 0;
       for( ; loc <= (strLen-subStrLen); loc++)
       {
           if (*pStr++ == *pSubStr)  // match first char
           {
               // point to substr 2nd char
               const Char16* p = pSubStr + 1;
   
               // Test remaining chars for equal
               Uint32 i = 1;
               for (; i < subStrLen; i++)
                   if (*pStr++ != *p++ )
                       {pStr--; break;} // break from loop
               if (i == subStrLen)
                   return loc;
           }
       }
       return -1;
   }
   // ATTN:KS 5 apr 2000 Need to add the Char16* version.
   Uint32 String::find(const char* s) const
   {
       return find(String(s));
   }
   
   Uint32 String::reverseFind(Char16 c) const
   {
       const Char16* first = getData();
       const Char16* last = getData() + getLength();
   
       while (last != first)
       {
           if (*--last == c)
               return last - first;
       }
   
       return Uint32(-1);
   }
   
 int String::compare(const Char16* s1, const Char16* s2) int String::compare(const Char16* s1, const Char16* s2)
 { {
     while (*s1 && *s2)     while (*s1 && *s2)
Line 321 
Line 401 
     return os;     return os;
 } }
  
 Boolean operator==(const String& x, const char* y)  
 {  
     return operator==(x, String(y));  
 }  
   
 Boolean operator==(const char* x, const String& y)  
 {  
     return operator==(String(x), y);  
 }  
   
 void String::toLower(char* str) void String::toLower(char* str)
 { {
     while (*str)     while (*str)


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2