Advertisement
Guest User

Untitled

a guest
Sep 19th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. bool match(string needle, string haystack) {
  2. if (needle.size() == 0 && haystack.size() == 0)
  3. return true;
  4. if (needle.size() == 0)
  5. return false;
  6. if (needle == "*")
  7. return true;
  8. if (needle[0] == '?')
  9. if (haystack.size() != 0)
  10. return match(needle.substring(1, needle.size()), haystack.substring(1, haystack.size()));
  11. else
  12. return false;
  13. if (needle[0] == '*') {
  14. auto char = needle[1];
  15. int index = 0;
  16. while(haystack[index] != char) {
  17. index++;
  18. if (index >= haystack.size())
  19. return false;
  20. }
  21. return match(needle.substring(1, needle.size()), haystack.substring(index, haystack.size()));
  22. }
  23. if (needle[0] == haystack[0])
  24. return match(needle.substring(1, needle.size()), haystack.substring(1, haystack.size()));
  25. return false;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement