mirror of
https://github.com/zeux/pugixml.git
synced 2025-01-14 18:07:59 +08:00
XPath: Replaced backtracking with lookahead in absolute path parsing
git-svn-id: http://pugixml.googlecode.com/svn/trunk@485 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
18848ef589
commit
4c0e67ae92
@ -881,12 +881,6 @@ namespace pugi
|
|||||||
return m_cur;
|
return m_cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset(const char_t* state)
|
|
||||||
{
|
|
||||||
m_cur = state;
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
|
|
||||||
void next()
|
void next()
|
||||||
{
|
{
|
||||||
contents_clear();
|
contents_clear();
|
||||||
@ -3079,25 +3073,17 @@ namespace pugi
|
|||||||
{
|
{
|
||||||
if (m_lexer.current() == lex_slash)
|
if (m_lexer.current() == lex_slash)
|
||||||
{
|
{
|
||||||
// Save state for next lexeme - that is, whatever follows '/'
|
|
||||||
const char_t* state = 0; // gcc3 "variable might be used uninitialized in this function" bug workaround
|
|
||||||
state = m_lexer.state();
|
|
||||||
|
|
||||||
m_lexer.next();
|
m_lexer.next();
|
||||||
|
|
||||||
xpath_ast_node* n = 0; // gcc3 "variable might be used uninitialized in this function" bug workaround
|
xpath_ast_node* n = new (m_alloc.node()) xpath_ast_node(ast_step_root, xpath_type_node_set);
|
||||||
n = new (m_alloc.node()) xpath_ast_node(ast_step_root, xpath_type_node_set);
|
|
||||||
|
// relative location path can start from axis_attribute, dot, double_dot, multiply and string lexemes; any other lexeme means standalone root path
|
||||||
try
|
lexeme_t l = m_lexer.current();
|
||||||
{
|
|
||||||
n = parse_relative_location_path(n);
|
if (l == lex_string || l == lex_axis_attribute || l == lex_dot || l == lex_double_dot || l == lex_multiply)
|
||||||
}
|
return parse_relative_location_path(n);
|
||||||
catch (const xpath_exception&)
|
else
|
||||||
{
|
return n;
|
||||||
m_lexer.reset(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
else if (m_lexer.current() == lex_double_slash)
|
else if (m_lexer.current() == lex_double_slash)
|
||||||
{
|
{
|
||||||
|
@ -254,4 +254,19 @@ TEST(xpath_parse_jaxen_invalid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_XML(xpath_parse_absolute, "<div><s/></div>")
|
||||||
|
{
|
||||||
|
CHECK_XPATH_NODESET(doc, STR("/")) % 1;
|
||||||
|
|
||||||
|
CHECK_XPATH_NODESET(doc, STR("/div/s")) % 3;
|
||||||
|
CHECK_XPATH_NODESET(doc, STR("/ div /s")) % 3;
|
||||||
|
CHECK_XPATH_FAIL(STR("/ div 5"));
|
||||||
|
|
||||||
|
CHECK_XPATH_NODESET(doc, STR("/*/s")) % 3;
|
||||||
|
CHECK_XPATH_NODESET(doc, STR("/ * /s")) % 3;
|
||||||
|
CHECK_XPATH_FAIL(STR("/ * 5"));
|
||||||
|
|
||||||
|
CHECK_XPATH_NODESET(doc, STR("/*[/]")) % 2;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user