cwText.h/cpp : Added firstMatchChar(char*,int,char) form of first char. match function.

This commit is contained in:
kevin 2024-11-17 14:51:55 -05:00
parent 1ed6202885
commit 638d3e8494
2 changed files with 17 additions and 0 deletions

View File

@ -158,6 +158,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

@ -67,6 +67,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 );