Fixed: #888 CSString::find and CSString::findNS broken

hg/feature/sound
kervala 15 years ago
parent e8d80432ba
commit 538f7abb14

@ -333,10 +333,10 @@ public:
CSString replace(const char *toFind,const char *replacement) const; CSString replace(const char *toFind,const char *replacement) const;
/// Find index at which a sub-string starts (case not sensitive) - if sub-string not found then returns string::npos /// Find index at which a sub-string starts (case not sensitive) - if sub-string not found then returns string::npos
unsigned find(const char *toFind,unsigned startLocation=0) const; std::string::size_type find(const char *toFind, std::string::size_type startLocation=0) const;
/// Find index at which a sub-string starts (case NOT sensitive) - if sub-string not found then returns string::npos /// Find index at which a sub-string starts (case NOT sensitive) - if sub-string not found then returns string::npos
unsigned findNS(const char *toFind,unsigned startLocation=0) const; std::string::size_type findNS(const char *toFind, std::string::size_type startLocation=0) const;
/// Return true if this contains given sub string /// Return true if this contains given sub string
bool contains(const char *toFind) const; bool contains(const char *toFind) const;
@ -346,8 +346,8 @@ public:
/// Handy atoi routines... /// Handy atoi routines...
int atoi() const; int atoi() const;
signed atosi() const; sint32 atosi() const;
unsigned atoui() const; uint32 atoui() const;
sint64 atoi64() const; sint64 atoi64() const;
sint64 atosi64() const; sint64 atosi64() const;
uint64 atoui64() const; uint64 atoui64() const;

@ -1325,7 +1325,7 @@ namespace NLMISC
if (toFind==NULL || *toFind==0) if (toFind==NULL || *toFind==0)
return *this; return *this;
unsigned i,j; std::string::size_type i,j;
CSString result; CSString result;
for (i=0;i<size();) for (i=0;i<size();)
{ {
@ -1349,15 +1349,15 @@ namespace NLMISC
return result; return result;
} }
unsigned CSString::find(const char *toFind,unsigned startLocation) const std::string::size_type CSString::find(const char *toFind, std::string::size_type startLocation) const
{ {
// const char *constStr = c_str(); // const char *constStr = c_str();
// just bypass the problems that can cause a crash... // just bypass the problems that can cause a crash...
if (toFind==NULL || *toFind==0 || startLocation>=size()) if (toFind==NULL || *toFind==0 || startLocation>=size())
return (unsigned)std::string::npos; return std::string::npos;
unsigned i,j; std::string::size_type i,j;
for (i=startLocation;i<size();++i) for (i=startLocation;i<size();++i)
{ {
// string compare toFind against (*this)+i ... // string compare toFind against (*this)+i ...
@ -1368,19 +1368,19 @@ namespace NLMISC
if (toFind[j]==0) if (toFind[j]==0)
return i; return i;
} }
return (unsigned)std::string::npos; return std::string::npos;
} }
/// Find index at which a sub-string starts (case NOT sensitive) - if sub-string not found then returns string::npos /// Find index at which a sub-string starts (case NOT sensitive) - if sub-string not found then returns string::npos
unsigned CSString::findNS(const char *toFind,unsigned startLocation) const std::string::size_type CSString::findNS(const char *toFind, std::string::size_type startLocation) const
{ {
const char *constStr = c_str(); const char *constStr = c_str();
// just bypass the problems that can cause a crash... // just bypass the problems that can cause a crash...
if (toFind==NULL || *toFind==0 || startLocation>=size()) if (toFind==NULL || *toFind==0 || startLocation>=size())
return (unsigned)std::string::npos; return std::string::npos;
unsigned i,j; std::string::size_type i,j;
for (i=startLocation;i<size();++i) for (i=startLocation;i<size();++i)
{ {
// string compare toFind against (*this)+i ... // string compare toFind against (*this)+i ...
@ -1391,12 +1391,12 @@ namespace NLMISC
if (toFind[j]==0) if (toFind[j]==0)
return i; return i;
} }
return (unsigned)std::string::npos; return std::string::npos;
} }
bool CSString::contains(const char *toFind) const bool CSString::contains(const char *toFind) const
{ {
return find(toFind)!=(unsigned)std::string::npos; return find(toFind)!=std::string::npos;
} }
bool CSString::contains(int character) const bool CSString::contains(int character) const
@ -1482,7 +1482,7 @@ namespace NLMISC
return neg? -(sint32)result: (sint32)result; return neg? -(sint32)result: (sint32)result;
} }
int CSString::atosi() const sint32 CSString::atosi() const
{ {
if (empty()) if (empty())
return 0; return 0;
@ -1533,7 +1533,7 @@ namespace NLMISC
return neg? -(sint32)result: (sint32)result; return neg? -(sint32)result: (sint32)result;
} }
unsigned CSString::atoui() const uint32 CSString::atoui() const
{ {
uint32 result=0; uint32 result=0;
for (const_iterator it=begin();it!=end();++it) for (const_iterator it=begin();it!=end();++it)

Loading…
Cancel
Save