XPath: Added error offset reporting
git-svn-id: http://pugixml.googlecode.com/svn/trunk@639 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
12607d6047
commit
608d5bbd79
@ -965,6 +965,7 @@ namespace pugi
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const char_t* m_cur;
|
const char_t* m_cur;
|
||||||
|
const char_t* m_cur_lexeme_pos;
|
||||||
xpath_lexer_string m_cur_lexeme_contents;
|
xpath_lexer_string m_cur_lexeme_contents;
|
||||||
|
|
||||||
lexeme_t m_cur_lexeme;
|
lexeme_t m_cur_lexeme;
|
||||||
@ -986,6 +987,9 @@ namespace pugi
|
|||||||
|
|
||||||
while (IS_CHARTYPEX(*cur, ctx_space)) ++cur;
|
while (IS_CHARTYPEX(*cur, ctx_space)) ++cur;
|
||||||
|
|
||||||
|
// save lexeme position for error reporting
|
||||||
|
m_cur_lexeme_pos = cur;
|
||||||
|
|
||||||
switch (*cur)
|
switch (*cur)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -1230,6 +1234,11 @@ namespace pugi
|
|||||||
return m_cur_lexeme;
|
return m_cur_lexeme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char_t* current_pos() const
|
||||||
|
{
|
||||||
|
return m_cur_lexeme_pos;
|
||||||
|
}
|
||||||
|
|
||||||
const xpath_lexer_string& contents() const
|
const xpath_lexer_string& contents() const
|
||||||
{
|
{
|
||||||
assert(m_cur_lexeme == lex_number || m_cur_lexeme == lex_string || m_cur_lexeme == lex_quoted_string);
|
assert(m_cur_lexeme == lex_number || m_cur_lexeme == lex_string || m_cur_lexeme == lex_quoted_string);
|
||||||
@ -2568,6 +2577,7 @@ namespace pugi
|
|||||||
{
|
{
|
||||||
xpath_allocator& m_alloc;
|
xpath_allocator& m_alloc;
|
||||||
xpath_lexer m_lexer;
|
xpath_lexer m_lexer;
|
||||||
|
const char_t* m_query;
|
||||||
xpath_parse_result* m_result;
|
xpath_parse_result* m_result;
|
||||||
jmp_buf m_error_handler;
|
jmp_buf m_error_handler;
|
||||||
|
|
||||||
@ -2577,7 +2587,7 @@ namespace pugi
|
|||||||
void throw_error(const char* message)
|
void throw_error(const char* message)
|
||||||
{
|
{
|
||||||
m_result->error = message;
|
m_result->error = message;
|
||||||
m_result->offset = 0; // $$$ lexer
|
m_result->offset = m_lexer.current_pos() - m_query;
|
||||||
|
|
||||||
longjmp(m_error_handler, 1);
|
longjmp(m_error_handler, 1);
|
||||||
}
|
}
|
||||||
@ -3332,7 +3342,7 @@ namespace pugi
|
|||||||
return parse_or_expression();
|
return parse_or_expression();
|
||||||
}
|
}
|
||||||
|
|
||||||
xpath_parser(const char_t* query, xpath_allocator& alloc, xpath_parse_result* result): m_alloc(alloc), m_lexer(query), m_result(result)
|
xpath_parser(const char_t* query, xpath_allocator& alloc, xpath_parse_result* result): m_alloc(alloc), m_lexer(query), m_query(query), m_result(result)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
TEST_XML(xpath_api_select_nodes, "<node><head/><foo/><foo/><tail/></node>")
|
TEST_XML(xpath_api_select_nodes, "<node><head/><foo/><foo/><tail/></node>")
|
||||||
@ -215,7 +216,7 @@ TEST(xpath_api_query_result_fail)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
xpath_query q(STR("string-length(1, 2, 3)"));
|
xpath_query q(STR("//foo/child::/bar"));
|
||||||
|
|
||||||
#ifndef PUGIXML_NO_EXCEPTIONS
|
#ifndef PUGIXML_NO_EXCEPTIONS
|
||||||
CHECK_FORCE_FAIL("Expected exception");
|
CHECK_FORCE_FAIL("Expected exception");
|
||||||
@ -228,7 +229,7 @@ TEST(xpath_api_query_result_fail)
|
|||||||
CHECK(!result);
|
CHECK(!result);
|
||||||
CHECK(result.error != 0 && result.error[0] != 0);
|
CHECK(result.error != 0 && result.error[0] != 0);
|
||||||
CHECK(result.description() == result.error);
|
CHECK(result.description() == result.error);
|
||||||
CHECK(result.offset == 0); // $$$
|
CHECK(result.offset == 13);
|
||||||
|
|
||||||
#ifndef PUGIXML_NO_EXCEPTIONS
|
#ifndef PUGIXML_NO_EXCEPTIONS
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user