tighten the loop in wildcard_string_match, eliminate a string copy operation
This commit is contained in:
parent
74aba095dc
commit
1053b35682
1 changed files with 6 additions and 11 deletions
|
@ -758,24 +758,19 @@ bool wildcard_string_match(const std::string& str, const std::string& match)
|
|||
do {
|
||||
matches = true;
|
||||
//now try to place the str into the solid space
|
||||
std::string test_str = str.substr(current);
|
||||
for(std::string::size_type i=0; i < solid_len; ++i) {
|
||||
if(i > test_str.length()) {
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
const std::string::size_type test_len = str.length() - current;
|
||||
for(std::string::size_type i=0; i < solid_len && matches; ++i) {
|
||||
char solid_c = match[solid_begin + i];
|
||||
if(solid_c != '?' && solid_c != test_str[i]) {
|
||||
if(i > test_len || !(solid_c == '?' || solid_c == str[current+i])) {
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(matches) {
|
||||
//the solid space matched, now consume it and attempt to find more
|
||||
std::string consumed_match = (solid_begin+solid_len < match.length())
|
||||
const std::string consumed_match = (solid_begin+solid_len < match.length())
|
||||
? match.substr(solid_end) : "";
|
||||
std::string consumed_str = (solid_len < test_str.length())
|
||||
? test_str.substr(solid_len) : "";
|
||||
const std::string consumed_str = (solid_len < test_len)
|
||||
? str.substr(current+solid_len) : "";
|
||||
matches = wildcard_string_match(consumed_str, consumed_match);
|
||||
}
|
||||
} while(wild_matching && !matches && ++current < str.length());
|
||||
|
|
Loading…
Add table
Reference in a new issue