cwText.h/cpp : Added firstMatchChar(0 and lastMatchChar().

This commit is contained in:
kevin 2023-11-19 15:03:42 -05:00
parent f42cb04752
commit d4d325c413
2 changed files with 34 additions and 0 deletions

View File

@ -82,6 +82,35 @@ const char* cw::nextNonWhiteChar( const char* s )
const char* cw::nextNonWhiteCharEOS( const char* s )
{ return _nextNonWhiteChar(s,true); }
const char* cw::firstMatchChar( const char* s, char c )
{
if( s == nullptr )
return nullptr;
for(; *s; ++s)
if(*s == c)
return s;
return nullptr;
}
const char* cw::lastMatchChar( const char* s, char c )
{
unsigned sn;
if( s == nullptr )
return nullptr;
sn = textLength(s);
if( sn == 0 )
return nullptr;
for(const char* s1=s+(sn-1); s<=s1; --s1)
if( *s1 == c )
return s1;
return nullptr;
}
bool cw::isInteger( const char* s )
{
for(; *s; ++s)

View File

@ -36,6 +36,11 @@ namespace cw
// or nullptr if 's' is null.
const char* nextNonWhiteCharEOS( const char* s );
// Return a pointer to the first occurrence of 'c' in s[] or nullptr
// if 'c' does not occur in s[]
const char* firstMatchChar( const char* s, char c );
// Find the last occurrent of 'c' in s[].
const char* lastMatchChar( const char* s, char c );
bool isInteger( const char* ); // text contains only [0-9]
bool isReal( const char* ); // text contains only [0-9] with one decimal place