Ticket #8728: matchString.patch
File matchString.patch, 4.1 KB (added by , 17 years ago) |
---|
-
home/david/Projects/scummvm/common/fs.cpp
26 26 #include "backends/fs/abstract-fs.h" 27 27 #include "backends/fs/abstract-fs-factory.h" 28 28 29 /**30 * Simple DOS-style pattern matching function (understands * and ? like used in DOS).31 * Taken from exult/files/listfiles.cc32 */33 static bool matchString(const char *str, const char *pat) {34 const char *p = 0;35 const char *q = 0;36 37 for (;;) {38 switch (*pat) {39 case '*':40 p = ++pat;41 q = str;42 break;43 44 default:45 if (*pat != *str) {46 if (p) {47 pat = p;48 str = ++q;49 if (!*str)50 return !*pat;51 break;52 }53 else54 return false;55 }56 // fallthrough57 case '?':58 if (!*str)59 return !*pat;60 pat++;61 str++;62 }63 }64 }65 66 29 FilesystemNode::FilesystemNode() { 67 30 _realNode = 0; 68 31 _refCount = 0; … … 233 196 return ((matches > 0) ? true : false); 234 197 } 235 198 236 // HACK HACK HACK237 extern const char *lastPathComponent(const Common::String &str);238 239 199 int FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const 240 200 { 241 201 FSList entries; … … 242 202 FSList children; 243 203 int matches = 0; 244 204 dir.getChildren(entries, FilesystemNode::kListAll, hidden); 245 205 246 206 //Breadth search (entries in the same level) 247 207 for (FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) { 248 208 if (entry->isDirectory()) { … … 248 208 if (entry->isDirectory()) { 249 209 children.push_back(*entry); 250 210 } else { 251 //TODO: here we assume all backends implement the lastPathComponent method. It is currently static, 252 // so it might be a good idea to include it inside the backend class. This would enforce its 253 // implementation by all ports. 254 if (matchString(lastPathComponent(entry->getPath()), filename.c_str())) { 211 if (Common::matchString(entry->getName().c_str(), filename.c_str())) { 255 212 results.push_back(*entry); 256 213 matches++; 257 214 -
home/david/Projects/scummvm/common/util.cpp
61 61 62 62 namespace Common { 63 63 64 bool matchString(const char *str, const char *pat) { 65 const char *p = 0; 66 const char *q = 0; 67 68 for (;;) { 69 switch (*pat) { 70 case '*': 71 p = ++pat; 72 q = str; 73 break; 74 75 default: 76 if (*pat != *str) { 77 if (p) { 78 pat = p; 79 str = ++q; 80 if (!*str) 81 return !*pat; 82 break; 83 } 84 else 85 return false; 86 } 87 // fallthrough 88 case '?': 89 if (!*str) 90 return !*pat; 91 pat++; 92 str++; 93 } 94 } 95 } 96 64 97 // 65 98 // Print hexdump of the data passed in 66 99 // -
home/david/Projects/scummvm/common/util.h
53 53 namespace Common { 54 54 55 55 /** 56 * Simple DOS-style pattern matching function (understands * and ? like used in DOS). 57 * Taken from exult/files/listfiles.cc 58 * 59 * Token meaning: 60 * "*": any character, any amount of times. 61 * "?": any character, only once. 62 * 63 * Example strings/patterns: 64 * String: monkey.s?? Pattern: monkey.s01 => true 65 * String: monkey.s?? Pattern: monkey.s101 => false 66 * String: monkey.s?1 Pattern: monkey.s99 => false 67 * String: monkey.s* Pattern: monkey.s101 => true 68 * String: monkey.s*1 Pattern: monkey.s99 => false 69 * 70 * @param str Text to be matched against the given pattern. 71 * @param pat Glob pattern. 72 * 73 * @return true if str matches the pattern, false otherwise. 74 */ 75 bool matchString(const char *str, const char *pat); 76 77 /** 56 78 * Print a hexdump of the data passed in. The number of bytes per line is 57 79 * customizable. 58 80 * @param data the data to be dumped