MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenShadingLanguage / osl_regex_impl

Function osl_regex_impl

src/liboslexec/opstring.cpp:132–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130
131
132OSL_SHADEOP int
133osl_regex_impl (void *sg_, const char *subject_, void *results, int nresults,
134 const char *pattern, int fullmatch)
135{
136 ShaderGlobals *sg = (ShaderGlobals *)sg_;
137 ShadingContext *ctx = sg->context;
138 const std::string &subject (ustring::from_unique(subject_).string());
139 match_results<std::string::const_iterator> mresults;
140 const regex &regex (ctx->find_regex (USTR(pattern)));
141 if (nresults > 0) {
142 std::string::const_iterator start = subject.begin();
143 int res = fullmatch ? regex_match (subject, mresults, regex)
144 : regex_search (subject, mresults, regex);
145 int *m = (int *)results;
146 for (int r = 0; r < nresults; ++r) {
147 if (r/2 < (int)mresults.size()) {
148 if ((r & 1) == 0)
149 m[r] = mresults[r/2].first - start;
150 else
151 m[r] = mresults[r/2].second - start;
152 } else {
153 m[r] = USTR(pattern).length();
154 }
155 }
156 return res;
157 } else {
158 return fullmatch ? regex_match (subject, regex)
159 : regex_search (subject, regex);
160 }
161}
162
163
164OSL_SHADEOP const char *

Callers

nothing calls this directly

Calls 2

beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected