|  | 
| 22 | 22 | 
 | 
| 23 | 23 | #include "plugin/x/src/xpl_regex.h" | 
| 24 | 24 | 
 | 
|  | 25 | +#include <memory> | 
|  | 26 | + | 
| 25 | 27 | #include "include/my_dbug.h" | 
| 26 | 28 | 
 | 
| 27 | 29 | namespace xpl { | 
| 28 | 30 | 
 | 
| 29 | 31 | Regex::Regex(const char *const pattern) | 
| 30 | 32 |     : m_status{U_ZERO_ERROR}, | 
| 31 |  | -      m_re{icu::UnicodeString::fromUTF8(pattern), UREGEX_CASE_INSENSITIVE, | 
| 32 |  | -           m_status} { | 
|  | 33 | +      m_pattern{icu::RegexPattern::compile( | 
|  | 34 | +          icu::UnicodeString::fromUTF8(pattern), UREGEX_CASE_INSENSITIVE, | 
|  | 35 | +          m_parse_error, m_status)} { | 
| 33 | 36 |   DBUG_ASSERT(U_SUCCESS(m_status)); | 
| 34 | 37 | } | 
| 35 | 38 | 
 | 
| 36 | 39 | bool xpl::Regex::match(const char *value) const { | 
| 37 |  | -  return U_SUCCESS(m_status) && | 
| 38 |  | -         m_re.reset(icu::UnicodeString::fromUTF8(value)).find(m_status); | 
|  | 40 | +  if (!U_SUCCESS(m_status)) return false; | 
|  | 41 | + | 
|  | 42 | +  UErrorCode match_status{U_ZERO_ERROR}; | 
|  | 43 | + | 
|  | 44 | +  /* Initializing RegexMatcher object with RegexPattern | 
|  | 45 | +   * can by done only by calling an RegexPattern method | 
|  | 46 | +   * that returns RegexMatcher pointer. | 
|  | 47 | +   * | 
|  | 48 | +   * RegexMatcher is not reentrant thus we need create an | 
|  | 49 | +   * instance per thread or like in current solution, | 
|  | 50 | +   * instance per xpl::Regex::match call. | 
|  | 51 | +   * | 
|  | 52 | +   * Other possibility would be to create RegexMatcher on stack | 
|  | 53 | +   * and parse the text patter each time that xpl::Regex::match | 
|  | 54 | +   * is called. | 
|  | 55 | +   */ | 
|  | 56 | +  std::unique_ptr<icu::RegexMatcher> regexp{ | 
|  | 57 | +      m_pattern->matcher(icu::UnicodeString::fromUTF8(value), match_status)}; | 
|  | 58 | + | 
|  | 59 | +  if (!U_SUCCESS(match_status)) return false; | 
|  | 60 | + | 
|  | 61 | +  return regexp->find(); | 
| 39 | 62 | } | 
| 40 | 63 | 
 | 
| 41 | 64 | }  // namespace xpl | 
0 commit comments