* xmlPatternCompileSafe: * @pattern: the pattern to compile * @dict: an optional dictionary for interned strings * @flags: compilation flags, see xmlPatternFlags * @namespaces: the prefix definitions, array of [URI, prefix] or NULL * @patternOut: output pattern * * Compile a pattern. * * Available since 2.13.0. * * Returns 0 on success, 1 on error, -1 if a memory allocation failed. */
| 2266 | * Returns 0 on success, 1 on error, -1 if a memory allocation failed. |
| 2267 | */ |
| 2268 | int |
| 2269 | xmlPatternCompileSafe(const xmlChar *pattern, xmlDict *dict, int flags, |
| 2270 | const xmlChar **namespaces, xmlPatternPtr *patternOut) { |
| 2271 | xmlPatternPtr ret = NULL, cur; |
| 2272 | xmlPatParserContextPtr ctxt = NULL; |
| 2273 | const xmlChar *or, *start; |
| 2274 | xmlChar *tmp = NULL; |
| 2275 | int type = 0; |
| 2276 | int streamable = 1; |
| 2277 | int error; |
| 2278 | |
| 2279 | if (patternOut == NULL) |
| 2280 | return(1); |
| 2281 | |
| 2282 | if (pattern == NULL) { |
| 2283 | error = 1; |
| 2284 | goto error; |
| 2285 | } |
| 2286 | |
| 2287 | start = pattern; |
| 2288 | or = start; |
| 2289 | while (*or != 0) { |
| 2290 | tmp = NULL; |
| 2291 | while ((*or != 0) && (*or != '|')) or++; |
| 2292 | if (*or == 0) |
| 2293 | ctxt = xmlNewPatParserContext(start, dict, namespaces); |
| 2294 | else { |
| 2295 | tmp = xmlStrndup(start, or - start); |
| 2296 | if (tmp != NULL) { |
| 2297 | ctxt = xmlNewPatParserContext(tmp, dict, namespaces); |
| 2298 | } |
| 2299 | or++; |
| 2300 | } |
| 2301 | if (ctxt == NULL) { |
| 2302 | error = -1; |
| 2303 | goto error; |
| 2304 | } |
| 2305 | cur = xmlNewPattern(); |
| 2306 | if (cur == NULL) { |
| 2307 | error = -1; |
| 2308 | goto error; |
| 2309 | } |
| 2310 | /* |
| 2311 | * Assign string dict. |
| 2312 | */ |
| 2313 | if (dict) { |
| 2314 | cur->dict = dict; |
| 2315 | xmlDictReference(dict); |
| 2316 | } |
| 2317 | if (ret == NULL) |
| 2318 | ret = cur; |
| 2319 | else { |
| 2320 | cur->next = ret->next; |
| 2321 | ret->next = cur; |
| 2322 | } |
| 2323 | cur->flags = flags; |
| 2324 | ctxt->comp = cur; |
| 2325 |
no test coverage detected