@@ -18,8 +18,20 @@ namespace {
18
18
* @return std::string Reformatted replace pattern
19
19
*/
20
20
std::string reformat_replace_pattern (std::string replace_pattern) {
21
- return std::regex_replace (replace_pattern, std::regex (R"( (\\)([0-9]+))" ), R"( $$2)" );
21
+ return std::regex_replace (replace_pattern, std::regex (R"( (?:\\)([0-9]+))" ), R"( $$1)" );
22
+ }
22
23
24
+ /* *
25
+ * @brief Fix old search pattern for backward compatibility
26
+ *
27
+ * @param search_pattern Search pattern to replace
28
+ * @return std::string Replaced search pattern
29
+ */
30
+ std::string fix_search_pattern (std::string search_pattern) {
31
+ if (search_pattern == R"( ([\\.\\?\\!,])| ('[ms])| (') | ('[rv]e)| (n't))" ) {
32
+ return R"( (?| ([\\.\\?\\!,])| ('[ms])| (') | ('[rv]e)| (n't)))" ;
33
+ }
34
+ return search_pattern;
23
35
}
24
36
25
37
} // namespace
@@ -36,8 +48,10 @@ m_global_replace(global_replace) {
36
48
auto replace_pattern_const = as_type_ptr<Constant>(arguments[pattern_input + 1 ].get_node_shared_ptr ());
37
49
auto search_pattern_buf = static_cast <const char *>(search_pattern_const->get_data_ptr ());
38
50
auto replace_pattern_buf = static_cast <const char *>(replace_pattern_const->get_data_ptr ());
39
- auto search_pattern = std::string (search_pattern_buf, search_pattern_const->get_byte_size ());
40
- m_replace_pattern = std::string (replace_pattern_buf, replace_pattern_const->get_byte_size ());
51
+ auto search_pattern = fix_search_pattern (std::string (search_pattern_buf, search_pattern_const->get_byte_size ()));
52
+ m_replace_pattern = reformat_replace_pattern (
53
+ std::string (replace_pattern_buf, replace_pattern_const->get_byte_size ())
54
+ );
41
55
42
56
m_search_pattern_pcre2 = std::make_shared<PCRE2Wrapper>(search_pattern);
43
57
@@ -66,7 +80,7 @@ RegexNormalization::RegexNormalization(
66
80
if (m_search_pattern_pcre2 == nullptr ) {
67
81
search_pattern_buf = static_cast <const char *>(search_pattern_const->get_data_ptr ());
68
82
replace_pattern_buf = static_cast <const char *>(replace_pattern_const->get_data_ptr ());
69
- search_pattern = std::string (search_pattern_buf, search_pattern_const->get_byte_size ());
83
+ search_pattern = fix_search_pattern ( std::string (search_pattern_buf, search_pattern_const->get_byte_size () ));
70
84
m_replace_pattern = std::string (replace_pattern_buf, replace_pattern_const->get_byte_size ());
71
85
m_replace_pattern = reformat_replace_pattern (m_replace_pattern);
72
86
m_search_pattern_pcre2 = std::make_shared<PCRE2Wrapper>(search_pattern);
@@ -100,7 +114,9 @@ bool RegexNormalization::evaluate(ov::TensorVector& outputs, const ov::TensorVec
100
114
// Write to common trie structures should be protected to prevent race conditions.
101
115
std::lock_guard<std::mutex> lock (m_mutex);
102
116
if (m_search_pattern_pcre2 == nullptr ) {
103
- std::string search_pattern = std::string (inputs[pattern_input].data <const char >(), inputs[pattern_input].get_size ());
117
+ std::string search_pattern = fix_search_pattern (
118
+ std::string (inputs[pattern_input].data <const char >(), inputs[pattern_input].get_size ())
119
+ );
104
120
m_replace_pattern = std::string (inputs[pattern_input + 1 ].data <const char >(), inputs[pattern_input + 1 ].get_size ());
105
121
m_replace_pattern = reformat_replace_pattern (m_replace_pattern);
106
122
m_search_pattern_pcre2 = std::make_shared<PCRE2Wrapper>(search_pattern);
0 commit comments