| 29 | } |
| 30 | |
| 31 | int parseCharOffset(const std::string& xpath) { |
| 32 | const size_t textPos = xpath.rfind("text()"); |
| 33 | const size_t dotPos = (textPos != std::string::npos) ? xpath.find('.', textPos) : xpath.rfind('.'); |
| 34 | if (dotPos == std::string::npos || dotPos + 1 >= xpath.size()) return 0; |
| 35 | int val = 0; |
| 36 | for (size_t i = dotPos + 1; i < xpath.size(); i++) { |
| 37 | if (xpath[i] < '0' || xpath[i] > '9') return 0; |
| 38 | val = val * 10 + (xpath[i] - '0'); |
| 39 | } |
| 40 | return val; |
| 41 | } |
| 42 | |
| 43 | // Parse the N from text()[N] in the XPath (1-based; defaults to 1 if absent or 1). |
| 44 | int parseTextNodeIndex(const std::string& xpath) { |