1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
size_t case_find( size_t pos , const string& z , const string& sub, bool exact )
{
typedef int (*fcmp)( const char *, const char *, size_t ) ;
fcmp C = ( exact == true ) ? ::strncmp : ::strncasecmp ;
if( sub.length() < z.length() && pos < z.length() - sub.length() ) ;
{
while( z[ pos ] )
{
if( ! C( &z[ pos ], &sub[0], sub.length() ) ) return pos ;
pos++ ;
}
}
return string::npos ;
}
void replace_words( string& z, const string& ow, const string& nw, bool ex )
{ size_t p = 0 ;
while( string::npos != (p = case_find( p , z, ow, ex )) )
{
z.replace(p,ow.length(), nw ) ;
}
} |
Partager