Commit 9685fec1 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/reader: Improve line number updating when switching to the next line.

parent 79a65678
...@@ -1050,16 +1050,29 @@ static int reader_cmp(xmlreader *reader, const WCHAR *str) ...@@ -1050,16 +1050,29 @@ static int reader_cmp(xmlreader *reader, const WCHAR *str)
return 0; return 0;
} }
static void reader_update_position(xmlreader *reader, WCHAR ch)
{
if (ch == '\r')
reader->position.line_position = 1;
else if (ch == '\n')
{
reader->position.line_number++;
reader->position.line_position = 1;
}
else
reader->position.line_position++;
}
/* moves cursor n WCHARs forward */ /* moves cursor n WCHARs forward */
static void reader_skipn(xmlreader *reader, int n) static void reader_skipn(xmlreader *reader, int n)
{ {
encoded_buffer *buffer = &reader->input->buffer->utf16; encoded_buffer *buffer = &reader->input->buffer->utf16;
const WCHAR *ptr = reader_get_ptr(reader); const WCHAR *ptr;
while (*ptr++ && n--) while (*(ptr = reader_get_ptr(reader)) && n--)
{ {
reader_update_position(reader, *ptr);
buffer->cur++; buffer->cur++;
reader->position.line_position++;
} }
} }
...@@ -1071,23 +1084,12 @@ static inline BOOL is_wchar_space(WCHAR ch) ...@@ -1071,23 +1084,12 @@ static inline BOOL is_wchar_space(WCHAR ch)
/* [3] S ::= (#x20 | #x9 | #xD | #xA)+ */ /* [3] S ::= (#x20 | #x9 | #xD | #xA)+ */
static int reader_skipspaces(xmlreader *reader) static int reader_skipspaces(xmlreader *reader)
{ {
encoded_buffer *buffer = &reader->input->buffer->utf16;
const WCHAR *ptr = reader_get_ptr(reader); const WCHAR *ptr = reader_get_ptr(reader);
UINT start = reader_get_cur(reader); UINT start = reader_get_cur(reader);
while (is_wchar_space(*ptr)) while (is_wchar_space(*ptr))
{ {
if (*ptr == '\r') reader_skipn(reader, 1);
reader->position.line_position = 0;
else if (*ptr == '\n')
{
reader->position.line_number++;
reader->position.line_position = 0;
}
else
reader->position.line_position++;
buffer->cur++;
ptr = reader_get_ptr(reader); ptr = reader_get_ptr(reader);
} }
......
...@@ -1590,6 +1590,7 @@ static void test_read_pending(void) ...@@ -1590,6 +1590,7 @@ static void test_read_pending(void)
ok(hr == S_OK || broken(hr == E_PENDING), "got 0x%08x\n", hr); ok(hr == S_OK || broken(hr == E_PENDING), "got 0x%08x\n", hr);
/* newer versions are happy when it's enough data to detect node type, /* newer versions are happy when it's enough data to detect node type,
older versions keep reading until it fails to read more */ older versions keep reading until it fails to read more */
todo_wine
ok(stream_readcall == 1 || broken(stream_readcall > 1), "got %d\n", stream_readcall); ok(stream_readcall == 1 || broken(stream_readcall > 1), "got %d\n", stream_readcall);
ok(type == XmlNodeType_Comment || broken(type == XmlNodeType_None), "got %d\n", type); ok(type == XmlNodeType_Comment || broken(type == XmlNodeType_None), "got %d\n", type);
...@@ -2474,7 +2475,7 @@ todo_wine { ...@@ -2474,7 +2475,7 @@ todo_wine {
static void test_reader_position(void) static void test_reader_position(void)
{ {
static const char *xml = "<c:a xmlns:c=\"nsdef c\" b=\"attr b\"></c:a>"; static const char *xml = "<c:a xmlns:c=\"nsdef c\" b=\"attr b\">\n</c:a>";
IXmlReader *reader; IXmlReader *reader;
XmlNodeType type; XmlNodeType type;
IStream *stream; IStream *stream;
...@@ -2529,8 +2530,14 @@ static void test_reader_position(void) ...@@ -2529,8 +2530,14 @@ static void test_reader_position(void)
hr = IXmlReader_Read(reader, &type); hr = IXmlReader_Read(reader, &type);
ok(hr == S_OK, "got %08x\n", hr); ok(hr == S_OK, "got %08x\n", hr);
ok(type == XmlNodeType_Whitespace, "got type %d\n", type);
todo_wine
TEST_READER_POSITION2(reader, 1, 35, 2, 6);
hr = IXmlReader_Read(reader, &type);
ok(hr == S_OK, "got %08x\n", hr);
ok(type == XmlNodeType_EndElement, "got type %d\n", type); ok(type == XmlNodeType_EndElement, "got type %d\n", type);
TEST_READER_POSITION2(reader, 1, 37, ~0u, 40); TEST_READER_POSITION2(reader, 2, 3, 2, 6);
IXmlReader_SetInput(reader, NULL); IXmlReader_SetInput(reader, NULL);
TEST_READER_STATE2(reader, XmlReadState_Initial, XmlReadState_Closed); TEST_READER_STATE2(reader, XmlReadState_Initial, XmlReadState_Closed);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment