version 1.4, 2001/02/26 04:33:28
|
version 1.9, 2001/04/11 07:03:02
|
|
|
// Author: | // Author: |
// | // |
// $Log$ | // $Log$ |
|
// Revision 1.9 2001/04/11 07:03:02 mike |
|
// Port to Unix |
|
// |
|
// 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 | // Revision 1.4 2001/02/26 04:33:28 mike |
// Fixed many places where cim names were be compared with operator==(String,String). |
// Fixed many places where cim names compared with operator==(String,String). |
// Changed all of these to use CIMName::equal() | // Changed all of these to use CIMName::equal() |
// | // |
// Revision 1.3 2001/02/11 17:19:30 mike | // Revision 1.3 2001/02/11 17:19:30 mike |
|
|
// | // |
//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; |
|
|
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 Uint32(-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 | Uint32 String::reverseFind(Char16 c) const |
{ | { |
const Char16* first = getData(); | const Char16* first = getData(); |