xmllite/reader: Improve line number updating when switching to the next line.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
79a65678fc
commit
9685fec174
|
@ -1050,16 +1050,29 @@ static int reader_cmp(xmlreader *reader, const WCHAR *str)
|
|||
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 */
|
||||
static void reader_skipn(xmlreader *reader, int n)
|
||||
{
|
||||
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++;
|
||||
reader->position.line_position++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1071,23 +1084,12 @@ static inline BOOL is_wchar_space(WCHAR ch)
|
|||
/* [3] S ::= (#x20 | #x9 | #xD | #xA)+ */
|
||||
static int reader_skipspaces(xmlreader *reader)
|
||||
{
|
||||
encoded_buffer *buffer = &reader->input->buffer->utf16;
|
||||
const WCHAR *ptr = reader_get_ptr(reader);
|
||||
UINT start = reader_get_cur(reader);
|
||||
|
||||
while (is_wchar_space(*ptr))
|
||||
{
|
||||
if (*ptr == '\r')
|
||||
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++;
|
||||
reader_skipn(reader, 1);
|
||||
ptr = reader_get_ptr(reader);
|
||||
}
|
||||
|
||||
|
|
|
@ -1590,6 +1590,7 @@ static void test_read_pending(void)
|
|||
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,
|
||||
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(type == XmlNodeType_Comment || broken(type == XmlNodeType_None), "got %d\n", type);
|
||||
|
||||
|
@ -2474,7 +2475,7 @@ todo_wine {
|
|||
|
||||
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;
|
||||
XmlNodeType type;
|
||||
IStream *stream;
|
||||
|
@ -2527,10 +2528,16 @@ static void test_reader_position(void)
|
|||
ok(hr == S_OK, "got %08x\n", hr);
|
||||
TEST_READER_POSITION2(reader, 1, 2, ~0u, 34);
|
||||
|
||||
hr = IXmlReader_Read(reader, &type);
|
||||
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);
|
||||
TEST_READER_POSITION2(reader, 1, 37, ~0u, 40);
|
||||
TEST_READER_POSITION2(reader, 2, 3, 2, 6);
|
||||
|
||||
IXmlReader_SetInput(reader, NULL);
|
||||
TEST_READER_STATE2(reader, XmlReadState_Initial, XmlReadState_Closed);
|
||||
|
|
Loading…
Reference in New Issue