* xmlXPtrMatchString: * @string: the string to search * @start: the start textnode * @startindex: the start index * @end: the end textnode IN/OUT * @endindex: the end index IN/OUT * * Check whether the document contains @string at the position * (@start, @startindex) and limited by the (@end, @endindex) point * * Returns -1 in case of failure, 0 if not found, 1 if found in which cas
| 2388 | * of the range |
| 2389 | */ |
| 2390 | static int |
| 2391 | xmlXPtrMatchString(const xmlChar *string, xmlNodePtr start, int startindex, |
| 2392 | xmlNodePtr *end, int *endindex) { |
| 2393 | xmlNodePtr cur; |
| 2394 | int pos; /* 0 based */ |
| 2395 | int len; /* in bytes */ |
| 2396 | int stringlen; /* in bytes */ |
| 2397 | int match; |
| 2398 | |
| 2399 | if (string == NULL) |
| 2400 | return(-1); |
| 2401 | if ((start == NULL) || (start->type == XML_NAMESPACE_DECL)) |
| 2402 | return(-1); |
| 2403 | if ((end == NULL) || (*end == NULL) || |
| 2404 | ((*end)->type == XML_NAMESPACE_DECL) || (endindex == NULL)) |
| 2405 | return(-1); |
| 2406 | cur = start; |
| 2407 | pos = startindex - 1; |
| 2408 | stringlen = xmlStrlen(string); |
| 2409 | |
| 2410 | while (stringlen > 0) { |
| 2411 | if ((cur == *end) && (pos + stringlen > *endindex)) |
| 2412 | return(0); |
| 2413 | |
| 2414 | if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { |
| 2415 | len = xmlStrlen(cur->content); |
| 2416 | if (len >= pos + stringlen) { |
| 2417 | match = (!xmlStrncmp(&cur->content[pos], string, stringlen)); |
| 2418 | if (match) { |
| 2419 | *end = cur; |
| 2420 | *endindex = pos + stringlen; |
| 2421 | return(1); |
| 2422 | } else { |
| 2423 | return(0); |
| 2424 | } |
| 2425 | } else { |
| 2426 | int sub = len - pos; |
| 2427 | match = (!xmlStrncmp(&cur->content[pos], string, sub)); |
| 2428 | if (match) { |
| 2429 | string = &string[sub]; |
| 2430 | stringlen -= sub; |
| 2431 | } else { |
| 2432 | return(0); |
| 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | cur = xmlXPtrAdvanceNode(cur, NULL); |
| 2437 | if (cur == NULL) |
| 2438 | return(0); |
| 2439 | pos = 0; |
| 2440 | } |
| 2441 | return(1); |
| 2442 | } |
| 2443 | |
| 2444 | /** |
| 2445 | * xmlXPtrSearchString: |
no test coverage detected