| 4606 | } |
| 4607 | |
| 4608 | xpath_step_t ParseXPathStep( const lChar16 * &path, lString16 & name, int & index ) |
| 4609 | { |
| 4610 | int pos = 0; |
| 4611 | const lChar16 * s = path; |
| 4612 | //int len = path.GetLength(); |
| 4613 | name.clear(); |
| 4614 | index = -1; |
| 4615 | int flgPrefix = 0; |
| 4616 | if (s && s[pos]) { |
| 4617 | lChar16 ch = s[pos]; |
| 4618 | // prefix: none, '/' or '.' |
| 4619 | if (ch=='/') { |
| 4620 | flgPrefix = 1; |
| 4621 | ch = s[++pos]; |
| 4622 | } else if (ch=='.') { |
| 4623 | flgPrefix = 2; |
| 4624 | ch = s[++pos]; |
| 4625 | } |
| 4626 | int nstart = pos; |
| 4627 | if (ch>='0' && ch<='9') { |
| 4628 | // node or point index |
| 4629 | pos++; |
| 4630 | while (s[pos]>='0' && s[pos]<='9') |
| 4631 | pos++; |
| 4632 | if (s[pos] && s[pos!='/'] && s[pos]!='.') |
| 4633 | return xpath_step_error; |
| 4634 | lString16 sindex( path+nstart, pos-nstart ); |
| 4635 | index = sindex.atoi(); |
| 4636 | if (index<((flgPrefix==2)?0:1)) |
| 4637 | return xpath_step_error; |
| 4638 | path += pos; |
| 4639 | return (flgPrefix==2) ? xpath_step_point : xpath_step_nodeindex; |
| 4640 | } |
| 4641 | while (s[pos] && s[pos]!='[' && s[pos]!='/' && s[pos]!='.') |
| 4642 | pos++; |
| 4643 | if (pos==nstart) |
| 4644 | return xpath_step_error; |
| 4645 | name = lString16( path+ nstart, pos-nstart ); |
| 4646 | if (s[pos]=='[') { |
| 4647 | // index |
| 4648 | pos++; |
| 4649 | int istart = pos; |
| 4650 | while (s[pos] && s[pos]!=']' && s[pos]!='/' && s[pos]!='.') |
| 4651 | pos++; |
| 4652 | if (!s[pos] || pos==istart) |
| 4653 | return xpath_step_error; |
| 4654 | |
| 4655 | lString16 sindex( path+istart, pos-istart ); |
| 4656 | index = sindex.atoi(); |
| 4657 | pos++; |
| 4658 | } |
| 4659 | if (!s[pos] || s[pos]=='/' || s[pos]=='.') { |
| 4660 | path += pos; |
| 4661 | return (name==L"text()") ? xpath_step_text : xpath_step_element; // OK! |
| 4662 | } |
| 4663 | return xpath_step_error; // error |
| 4664 | } |
| 4665 | return xpath_step_error; |
no test coverage detected