You know when you search for a file using something like *.mp3 or whatever, does anyone have any code that will determine if a particular string matches a particular mask?
You know when you search for a file using something like *.mp3 or whatever, does anyone have any code that will determine if a particular string matches a particular mask?
C Code. C Code Run. Run Code Run... Please!
"Love is like a blackhole, you fall into it... then you get ripped apart"
This is (presumably) OS specific. You'll need to tell us what OS you're using...
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Im using Windows...
C Code. C Code Run. Run Code Run... Please!
"Love is like a blackhole, you fall into it... then you get ripped apart"
Hmmm, not quite what I had in mind. More like this...
Basically I need an implementation for 'DoesFilenameMatchMask'. I'd write one myself but im kinda busy with other stuff right now and its implementation seemed like it would be kinda involved.Code:string fname = "Eine Kleine Nachtmusik.mp3", mask = "*ee*ven*.mp?"; if (DoesFilenameMatchMask(fname, mask)) cout << "We have a match" << endl; else cout << "No match" << endl;
C Code. C Code Run. Run Code Run... Please!
"Love is like a blackhole, you fall into it... then you get ripped apart"
Unfortunately none of those pages seemed to actually have the source code on them... so I ended up writing my own
Here it is if anyone wants it. If anyone has a more efficient implementation i'd like to see it
Code:bool MatchMask(const char *str, const char *mask) { char c; const char *p; while (*mask) { c = *mask++; if (c == '*') { while (*mask == '*' && *mask) mask++; if (*mask) { p = str; while (*p) { while (*p && *p != *mask) p++; if (MatchMask(p, mask)) return true; p++; } } else return true; } else if (c == '?') { if (!*str) return false; } else if (c != *str) { return false; } str++; } return !*mask && !*str; }
C Code. C Code Run. Run Code Run... Please!
"Love is like a blackhole, you fall into it... then you get ripped apart"