version 1.5, 2001/03/09 19:49:32
|
version 1.11, 2001/04/14 07:35:05
|
|
|
// Author: | // Author: |
// | // |
// $Log$ | // $Log$ |
|
// Revision 1.11 2001/04/14 07:35:05 mike |
|
// Added config file loading to OptionManager |
|
// |
|
// Revision 1.10 2001/04/11 19:53:22 mike |
|
// More porting |
|
// |
|
// 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 | // Revision 1.5 2001/03/09 19:49:32 karl |
// long lines | // long lines |
// | // |
|
|
// | // |
//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(); |
|
|
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 |