version 1.4, 2001/02/26 04:33:28
|
version 1.15, 2001/04/27 22:28:32
|
|
|
//BEGIN_LICENSE |
//%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM | // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM |
// | // |
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
// DEALINGS IN THE SOFTWARE. | // DEALINGS IN THE SOFTWARE. |
// | // |
//END_LICENSE |
//============================================================================== |
//BEGIN_HISTORY |
|
// | // |
// Author: |
// Author: Mike Brasher (mbrasher@bmc.com) |
// | // |
// $Log$ |
// Modified By: |
// Revision 1.4 2001/02/26 04:33:28 mike |
|
// Fixed many places where cim names were be 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 |
|
// new |
|
// |
|
// Revision 1.1.1.1 2001/01/14 19:53:14 mike |
|
// Pegasus import |
|
// |
|
// |
|
//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 equal(String(x), y); | return equal(String(x), y); |
} | } |
| |
|
Boolean String::equalIgnoreCase(const String& x, const String& y) |
|
{ |
|
if (x.getLength() != y.getLength()) |
|
return false; |
|
|
|
const Char16* p = x.getData(); |
|
const Char16* q = y.getData(); |
|
|
|
Uint32 n = x.getLength(); |
|
|
|
while (n--) |
|
{ |
|
if (*p <= 127 && *q <= 127) |
|
{ |
|
if (tolower(*p++) != tolower(*q++)) |
|
return false; |
|
} |
|
else if (*p++ != *q++) |
|
return false; |
|
} |
|
|
|
return true; |
|
} |
| |
String String::subString(Uint32 pos, Uint32 length) const | String String::subString(Uint32 pos, Uint32 length) const |
{ | { |
|
|
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(); |
|
|
return Uint32(-1); | return Uint32(-1); |
} | } |
| |
|
void String::toLower() |
|
{ |
|
for (Char16* p = &_rep[0]; *p; p++) |
|
{ |
|
if (*p <= 127) |
|
*p = tolower(*p); |
|
} |
|
} |
|
|
|
void String::translate(Char16 fromChar, Char16 toChar) |
|
{ |
|
for (Char16* p = &_rep[0]; *p; p++) |
|
{ |
|
if (*p == fromChar) |
|
*p = toChar; |
|
} |
|
} |
|
|
int String::compare(const Char16* s1, const Char16* s2) | int String::compare(const Char16* s1, const Char16* s2) |
{ | { |
while (*s1 && *s2) | while (*s1 && *s2) |
|
|
return tmp; | return tmp; |
} | } |
| |
|
int CompareIgnoreCase(const char* s1, const char* s2) |
|
{ |
|
while (*s1 && *s2) |
|
{ |
|
int r = tolower(*s1++) - tolower(*s2++); |
|
|
|
if (r) |
|
return r; |
|
} |
|
|
|
if (*s2) |
|
return -1; |
|
else if (*s1) |
|
return 1; |
|
|
|
return 0; |
|
} |
|
|
|
Boolean GetLine(istream& is, String& line) |
|
{ |
|
line.clear(); |
|
|
|
Boolean gotChar = false; |
|
char c; |
|
|
|
while (is.get(c)) |
|
{ |
|
gotChar = true; |
|
|
|
if (c == '\n') |
|
break; |
|
|
|
line.append(c); |
|
} |
|
|
|
return gotChar; |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |