* xmlXPtrSearchString: * @string: the string to search * @start: the start textnode IN/OUT * @startindex: the start index IN/OUT * @end: the end textnode * @endindex: the end index * * Search the next occurrence of @string within the document content * until the (@end, @endindex) point is reached * * Returns -1 in case of failure, 0 if not found, 1 if found in which case *
| 2458 | * of the range |
| 2459 | */ |
| 2460 | static int |
| 2461 | xmlXPtrSearchString(const xmlChar *string, xmlNodePtr *start, int *startindex, |
| 2462 | xmlNodePtr *end, int *endindex) { |
| 2463 | xmlNodePtr cur; |
| 2464 | const xmlChar *str; |
| 2465 | int pos; /* 0 based */ |
| 2466 | int len; /* in bytes */ |
| 2467 | xmlChar first; |
| 2468 | |
| 2469 | if (string == NULL) |
| 2470 | return(-1); |
| 2471 | if ((start == NULL) || (*start == NULL) || |
| 2472 | ((*start)->type == XML_NAMESPACE_DECL) || (startindex == NULL)) |
| 2473 | return(-1); |
| 2474 | if ((end == NULL) || (endindex == NULL)) |
| 2475 | return(-1); |
| 2476 | cur = *start; |
| 2477 | pos = *startindex - 1; |
| 2478 | first = string[0]; |
| 2479 | |
| 2480 | while (cur != NULL) { |
| 2481 | if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { |
| 2482 | len = xmlStrlen(cur->content); |
| 2483 | while (pos <= len) { |
| 2484 | if (first != 0) { |
| 2485 | str = xmlStrchr(&cur->content[pos], first); |
| 2486 | if (str != NULL) { |
| 2487 | pos = (str - (xmlChar *)(cur->content)); |
| 2488 | if (xmlXPtrMatchString(string, cur, pos + 1, |
| 2489 | end, endindex)) { |
| 2490 | *start = cur; |
| 2491 | *startindex = pos + 1; |
| 2492 | return(1); |
| 2493 | } |
| 2494 | pos++; |
| 2495 | } else { |
| 2496 | pos = len + 1; |
| 2497 | } |
| 2498 | } else { |
| 2499 | /* |
| 2500 | * An empty string is considered to match before each |
| 2501 | * character of the string-value and after the final |
| 2502 | * character. |
| 2503 | */ |
| 2504 | *start = cur; |
| 2505 | *startindex = pos + 1; |
| 2506 | *end = cur; |
| 2507 | *endindex = pos + 1; |
| 2508 | return(1); |
| 2509 | } |
| 2510 | } |
| 2511 | } |
| 2512 | if ((cur == *end) && (pos >= *endindex)) |
| 2513 | return(0); |
| 2514 | cur = xmlXPtrAdvanceNode(cur, NULL); |
| 2515 | if (cur == NULL) |
| 2516 | return(0); |
| 2517 | pos = 1; |
no test coverage detected