cwText.h/cpp : Added firstMatchChar(s,n,c).

This commit is contained in:
kevin 2024-12-20 13:17:50 -05:00
parent b6296bcebe
commit a1735740c7
2 changed files with 17 additions and 0 deletions

View File

@ -160,6 +160,21 @@ char* cw::firstMatchChar( char* s, char c )
}
const char* cw::firstMatchChar( const char* s, char c )
{ return firstMatchChar((char*)s,c); }
char* cw::firstMatchChar( char* s, unsigned n, char c )
{
if( s == nullptr )
return nullptr;
for(unsigned i=0; *s && i<n; ++s,++i)
if(*s == c)
return s;
return nullptr;
}
const char* cw::firstMatchChar( const char* s, unsigned n, char c )
{
return firstMatchChar((char*)s,c);
}

View File

@ -69,6 +69,8 @@ namespace cw
// if 'c' does not occur in s[]
char* firstMatchChar( char* s, char c );
const char* firstMatchChar( const char* s, char c );
char* firstMatchChar( char* s, unsigned sn, char c );
const char* firstMatchChar( const char* s, unsigned sn, char c );
// Find the last occurrent of 'c' in s[].
char* lastMatchChar( char* s, char c );