Mercurial > hg > orthanc
diff OrthancServer/Search/WildcardConstraint.cpp @ 2331:a47d07b5b39f
Fix issue #56 (case-insensitive matching over accents)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Jul 2017 17:29:18 +0200 |
parents | a3a65de1840f |
children | 878b59270859 |
line wrap: on
line diff
--- a/OrthancServer/Search/WildcardConstraint.cpp Fri Jul 14 16:34:16 2017 +0200 +++ b/OrthancServer/Search/WildcardConstraint.cpp Fri Jul 14 17:29:18 2017 +0200 @@ -42,6 +42,24 @@ { boost::regex pattern_; std::string wildcard_; + bool isCaseSensitive_; + + PImpl(const std::string& wildcard, + bool isCaseSensitive) + { + isCaseSensitive_ = isCaseSensitive; + + if (isCaseSensitive) + { + wildcard_ = wildcard; + } + else + { + wildcard_ = Toolbox::ToUpperCaseWithAccents(wildcard); + } + + pattern_ = boost::regex(Toolbox::WildcardToRegularExpression(wildcard_)); + } }; @@ -53,25 +71,20 @@ WildcardConstraint::WildcardConstraint(const std::string& wildcard, bool isCaseSensitive) : - pimpl_(new PImpl) + pimpl_(new PImpl(wildcard, isCaseSensitive)) { - pimpl_->wildcard_ = wildcard; - - std::string re = Toolbox::WildcardToRegularExpression(wildcard); - - if (isCaseSensitive) - { - pimpl_->pattern_ = boost::regex(re); - } - else - { - pimpl_->pattern_ = boost::regex(re, boost::regex::icase /* case insensitive search */); - } } bool WildcardConstraint::Match(const std::string& value) const { - return boost::regex_match(value, pimpl_->pattern_); + if (pimpl_->isCaseSensitive_) + { + return boost::regex_match(value, pimpl_->pattern_); + } + else + { + return boost::regex_match(Toolbox::ToUpperCaseWithAccents(value), pimpl_->pattern_); + } } void WildcardConstraint::Setup(LookupIdentifierQuery& lookup,