I came up with this implementation of substring method. Anyone got ideas to make it more terse and more efficient?
bool substring(const char* str, const char* substr){
const char *currentString = str, *backTrackString = str, *currSubstr = substr;
while( strlen(backTrackString) >= strlen(substr) ){
while( *currSubstr && *currentString++ == *currSubstr++);
if( !*currSubstr ) return true;
currentString = backTrackString++;
currSubstr = substr;
}
return false;
}
In particular, can we do without atleast one of the local variables - while still being as efficient or better? A more basic question - so you think this is efficient?