cwText.h/cpp : Added first/lastMatchChar() for non-const strings.
This commit is contained in:
parent
66c1f08c16
commit
a3012db165
16
cwText.cpp
16
cwText.cpp
@ -146,7 +146,7 @@ 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 )
|
||||
char* cw::firstMatchChar( char* s, char c )
|
||||
{
|
||||
if( s == nullptr )
|
||||
return nullptr;
|
||||
@ -157,7 +157,12 @@ const char* cw::firstMatchChar( const char* s, char c )
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* cw::lastMatchChar( const char* s, char c )
|
||||
const char* cw::firstMatchChar( const char* s, char c )
|
||||
{
|
||||
return firstMatchChar((char*)s,c);
|
||||
}
|
||||
|
||||
char* cw::lastMatchChar( char* s, char c )
|
||||
{
|
||||
unsigned sn;
|
||||
|
||||
@ -168,13 +173,18 @@ const char* cw::lastMatchChar( const char* s, char c )
|
||||
if( sn == 0 )
|
||||
return nullptr;
|
||||
|
||||
for(const char* s1=s+(sn-1); s<=s1; --s1)
|
||||
for(char* s1=s+(sn-1); s<=s1; --s1)
|
||||
if( *s1 == c )
|
||||
return s1;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* cw::lastMatchChar( const char* s, char c )
|
||||
{
|
||||
return lastMatchChar((char*)s,c);
|
||||
}
|
||||
|
||||
bool cw::isInteger( const char* s )
|
||||
{
|
||||
for(; *s; ++s)
|
||||
|
3
cwText.h
3
cwText.h
@ -65,8 +65,11 @@ namespace cw
|
||||
|
||||
// Return a pointer to the first occurrence of 'c' in s[] or nullptr
|
||||
// if 'c' does not occur in s[]
|
||||
char* firstMatchChar( char* s, char c );
|
||||
const char* firstMatchChar( const char* s, char c );
|
||||
|
||||
// Find the last occurrent of 'c' in s[].
|
||||
char* lastMatchChar( char* s, char c );
|
||||
const char* lastMatchChar( const char* s, char c );
|
||||
|
||||
bool isInteger( const char* ); // text contains only [0-9]
|
||||
|
Loading…
Reference in New Issue
Block a user