regex filter: if string is invalid utf-8, ignore it

This commit is contained in:
Andrzej Rybczak
2015-08-15 11:51:19 +02:00
parent 83c856773e
commit 51768b9f7a

View File

@@ -56,13 +56,18 @@ inline Regex make(StringT &&s, boost::regex_constants::syntax_option_type flags)
template <typename StringT> template <typename StringT>
inline bool search(StringT &&s, const Regex &rx) inline bool search(StringT &&s, const Regex &rx)
{ {
return try {
# ifdef BOOST_REGEX_ICU return
boost::u32regex_search # ifdef BOOST_REGEX_ICU
# else boost::u32regex_search
boost::regex_search # else
# endif // BOOST_REGEX_ICU boost::regex_search
(std::forward<StringT>(s), rx); # endif // BOOST_REGEX_ICU
(std::forward<StringT>(s), rx);
} catch (std::out_of_range &) {
// Invalid UTF-8 sequence, ignore the string.
return false;
}
} }
template <typename T> template <typename T>