
Hi, I was wondering if boost string algorithms library has any support for "wildcard" characters (eg * and ?). If not... then I'm open to suggestions :) Cheers, Richard

Cheers. I was rather hoping not to have to use regular expressions;
they're kinda beyond the intended users of my program (it's for a
user-defined filter function, and I don't expect them to be familiar
with regex syntax).
I cheaped out and used an old C wildcmp(wild.c_str(), text.c_str())
method instead.
Thanks,
Richard
On 9/8/06, Pavol Droba

You can translate from wildcards syntax to regex one and then use string_algo that supports regex. For example: std::string wildcards_to_regex(std::string const& wildcard_pattern) { // replaces wildcards by corresponding regex expressions // mask all regex special characters (except wildcards characters "*?") std::string regex_pattern = boost::algorithm::replace_all_regex_copy(wildcard_pattern, boost::regex("[\\.\\[\\]\\{\\}\\(\\)\\\\\\+\\|\\^\\$]"), std::string("\\\\$&")); // replace wildcards by corresponding regex's boost::algorithm::replace_all_regex(regex_pattern, boost::regex("\\*"), std::string("\\.\\*")); boost::algorithm::replace_all_regex(regex_pattern, boost::regex("\\?"), std::string("\\.{1}")); return regex_pattern; } Test: assert(wildcards_to_regex("+[*?") == "\\+\\[.*.{1}"); To community and especially to Pavol Droba as the author of string_algo: What do you think about popularity of wildcards as the tool for end-users? Is it worth to add wildcards support to the library? To what library? Is the boost-development mailing list a better place for this discussion? Best regards, Andriy Tylychko, telia@vichnavich.com www.vichnavich.com

Hi, Andriy Tylychko (mail.ru) wrote:
I can only express my personal opinion here and that is : the wildcards should not be a directly supported in string_algo library. Reason is simple: the functionality provided by wildcards is superseeded by regex in all respects. In addition, as you have explained in your previous mail, it is easy to convert a wildcard to a regex. I can't say if the support could be incorporated into Boost.Regex. This library already support several syntaxes, so wildcards could be just another variant. But this is more question to John Maddock. You can also try to cleanup your conversion utility and offer it to boost, to get a response from whole comunity. Regards, Pavol
participants (4)
-
Andriy Tylychko (mail.ru)
-
François Duranleau
-
Pavol Droba
-
Richard Dingwall