stringutil.h
namespace StringUtils
{
namespace impl
{
inline bool startsWith(const char* s1, const char* s2);
}
inline const char* strstr(const char* s1, const char* s2)
{
char ch = s2[0];
if(0 == ch)
return s1;
while(*s1)
{
if(*s1 == ch && impl::startsWith(s1, s2))
return s1;
++s1;
}
return 0;
}
inline void toupper(const char* s1, char* s2)
{
int ch = *s1;
while(ch != 0)
{
if(ch >= 'a' && ch <= 'z')
*s2 = ch - 32;
else
*s2 = ch;
++s1;
++s2;
ch = *s1;
}
*s2 = 0;
}
inline void tolower(const char* s1, char* s2)
{
int ch = *s1;
while(ch != 0)
{
if(ch >= 'A' && ch <= 'Z')
*s2 = ch + 32;
else
*s2 = ch;
++s1;
++s2;
ch = *s1;
}
*s2 = 0;
}
namespace impl
{
inline bool startsWith(const char* s1, const char* s2)
{
while(*s1 && *s2)
{
if(*s1++ != *s2++)
return false;
}
if(*s2)
return false;
return true;
}
}
}
|
|
|
|