Fixed g++ std::string incompatibility

This commit is contained in:
Ianos Gnatiuc
2006-02-24 08:53:21 +00:00
parent f2c63a70a9
commit 5fb7f95cb8
4 changed files with 57 additions and 60 deletions

View File

@@ -62,7 +62,6 @@ int strchg(char* str, char oldch, char newch);
char* stridela(const char* substr, char* str);
int strnicmpw(const char* str1, const char* str2, int len);
const char* striinc(const char* str1, const char* str2);
std::string::iterator striinc(const char* str1, std::string &str2);
char* strins(const char* instr, char* str, int st_pos);
char* strisrep(char* str, const char* search, const char* replace);
char* strischg(char* str, const char* find, const char* replace);

View File

@@ -150,22 +150,6 @@ const char* striinc(const char* str1, const char* str2) {
}
// ------------------------------------------------------------------
// Determines if string1 is included in string2
std::string::iterator striinc(const char* str1, std::string &str2)
{
int max = strlen(str1);
std::string::iterator it;
for (it = str2.begin(); it != str2.end(); it++)
if (!strnicmp(str1, it, max))
return it;
return str2.end(); // string1 not found in string2
}
// ------------------------------------------------------------------
// Inserts one string into another
@@ -232,18 +216,20 @@ char* strischg(char* str, const char* find, const char* replace) {
void strischg(std::string &str, const char* find, const char* replace)
{
int lenf = strlen(find);
int lenr = strlen(replace);
size_t lenf = strlen(find);
size_t lenr = strlen(replace);
size_t length = str.length();
std::string::iterator it;
for (it = str.begin(); it != str.end(); it++)
for (size_t pos = 0; pos < length; )
{
if (strnieql(find, it, lenf))
if (strnieql(&(str.c_str()[pos]), find, lenf))
{
size_t idx = it - str.begin();
str.replace(it, it+lenf, replace, lenr);
it = str.begin() + idx + lenr - 1;
str.replace(pos, lenf, replace, lenr);
pos += lenr;
length = str.length();
}
else
pos++;
}
}