| 350 | } |
| 351 | |
| 352 | static bool Matches(const TChar* Str, const TChar* Mask) { |
| 353 | /* |
| 354 | Dr.Dobb's Algorithm: |
| 355 | http://www.drdobbs.com/architecture-and-design/matching-wildcards-an-empirical-way-to-t/240169123?queryText=path%2Bmatches |
| 356 | */ |
| 357 | |
| 358 | const TChar* TameText = Str; |
| 359 | const TChar* WildText = Mask; |
| 360 | const TChar* TameBookmark = static_cast<TChar*>(0x00); |
| 361 | const TChar* WildBookmark = static_cast<TChar*>(0x00); |
| 362 | |
| 363 | while (true) { |
| 364 | if (*WildText == static_cast<TChar>('*')) { |
| 365 | while (*(++WildText) == static_cast<TChar>('*')); // "xy" matches "x**y" |
| 366 | if (!*WildText) return true; // "x" matches "*" |
| 367 | |
| 368 | if (*WildText != static_cast<TChar>('?')) { |
| 369 | while (*TameText != *WildText) { |
| 370 | if (!(*(++TameText))) |
| 371 | return false; // "x" doesn't match "*y*" |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | WildBookmark = WildText; |
| 376 | TameBookmark = TameText; |
| 377 | } |
| 378 | else if (*TameText != *WildText && *WildText != static_cast<TChar>('?')) { |
| 379 | if (WildBookmark) { |
| 380 | if (WildText != WildBookmark) { |
| 381 | WildText = WildBookmark; |
| 382 | |
| 383 | if (*TameText != *WildText) { |
| 384 | TameText = ++TameBookmark; |
| 385 | continue; // "xy" matches "*y" |
| 386 | } |
| 387 | else { |
| 388 | WildText++; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | if (*TameText) { |
| 393 | TameText++; |
| 394 | continue; // "mississippi" matches "*sip*" |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | return false; // "xy" doesn't match "x" |
| 399 | } |
| 400 | |
| 401 | TameText++; |
| 402 | WildText++; |
| 403 | |
| 404 | if (!*TameText) { |
| 405 | while (*WildText == static_cast<TChar>('*')) WildText++; // "x" matches "x*" |
| 406 | |
| 407 | if (!*WildText) return true; // "x" matches "x" |
| 408 | return false; // "x" doesn't match "xy" |
| 409 | } |
nothing calls this directly
no outgoing calls
no test coverage detected