MCPcopy Create free account
hub / github.com/TheHPXProject/hpx / regex_from_pattern

Function regex_from_pattern

libs/core/util/src/regex_from_pattern.cpp:65–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63 } // namespace detail
64
65 std::string regex_from_pattern(std::string const& pattern, error_code& ec)
66 {
67 std::string result;
68 auto const end = pattern.end();
69 for (auto it = pattern.begin(); it != end; ++it)
70 {
71 switch (char const c = *it)
72 {
73 case '*':
74 result.append(".*");
75 break;
76
77 case '?':
78 result.append(1, '.');
79 break;
80
81 case '[':
82 {
83 std::string r = detail::regex_from_character_set(it, end, ec);
84 if (ec)
85 return "";
86 result.append(r);
87 }
88 break;
89
90 case '\\':
91 if (++it == end)
92 {
93 HPX_THROWS_IF(ec, hpx::error::bad_parameter,
94 "regex_from_pattern", "Invalid escape sequence at: {}",
95 pattern);
96 return "";
97 }
98 result.append(1, *it);
99 break;
100
101 // escape regex special characters
102 // NOLINTNEXTLINE(bugprone-branch-clone)
103 case '+':
104 [[fallthrough]];
105 case '.':
106 [[fallthrough]];
107 case '(':
108 [[fallthrough]];
109 case ')':
110 [[fallthrough]];
111 case '{':
112 [[fallthrough]];
113 case '}':
114 [[fallthrough]];
115 case '^':
116 [[fallthrough]];
117 case '$':
118 result.append("\\");
119 [[fallthrough]];
120
121 default:
122 result.append(1, c);

Callers 5

counter_discovererMethod · 0.85
iterateMethod · 0.85
discover_counter_typeMethod · 0.85

Calls 4

regex_from_character_setFunction · 0.85
endMethod · 0.45
beginMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected