Reputation:
I'm trying to implement glob(3)
, or glob
-alike function in C++.
I already have a function that reads directory contents into an std::vector<std::string>
container (let's call this function ListDirectory()
), so I'd obviously only need the stringmatching part - My questions:
scanf
and friends)?Upvotes: 2
Views: 2221
Reputation: 76519
I use this one: wildcmp, in a mildly adapted form to reject directory seperators /
in a *
. If you want the slightly adapted code (I also converted the pointers to strings/iterators, for the fun of it :)
). It's clean and simple, no need for anything more fancy.
Upvotes: 0
Reputation: 11659
If you are searching platform independent wildcard library, for example, there is shwild library.
If you are examining pattern matching for self-educational purpose, as for basic regular expression by backtracking, I think chapter one of Beautiful Code illustrates well.
When once you are at home in regular expression, probably converting wildcard to regular expression, or converting regular expression code to wildcard matcher, won't be a hard job.
With regard to realistic regular expression by NFA, detailed explanations will be found in Russ Cox's web site.
Hope this helps
Upvotes: 3