From 3d4ad645bdbc1d1722171f99c3ef1a651575f7c1 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Wed, 23 Jul 2008 16:39:12 +0200 Subject: [PATCH] msxml3: Change ISAXXMLReader_characters implementation so it works correctly on files with '\r' characters. --- dlls/msxml3/saxreader.c | 62 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/dlls/msxml3/saxreader.c b/dlls/msxml3/saxreader.c index 2c0873fcf05..ef3c7e8f49c 100644 --- a/dlls/msxml3/saxreader.c +++ b/dlls/msxml3/saxreader.c @@ -254,24 +254,72 @@ static void libxmlCharacters( saxlocator *This = ctx; HRESULT hr; xmlChar *end; + xmlChar *lastCurCopy; + xmlChar *chEnd; + int columnCopy; + int lineCopy; + + if(*(This->lastCur-1) != '>' && *(This->lastCur-1) != '/') return; if(*(This->lastCur-1) != '>') { end = (xmlChar*)This->pParserCtxt->input->cur-len; + while(*(end-1) != '>') end--; update_position(This, end); } + chEnd = This->lastCur+len; + while(*chEnd != '<') chEnd++; + + Chars = bstr_from_xmlChar(ch); + + lastCurCopy = This->lastCur; + columnCopy = This->column; + lineCopy = This->line; + end = This->lastCur; + if(This->saxreader->contentHandler) { - Chars = bstr_from_xmlChar(ch); - hr = ISAXContentHandler_characters(This->saxreader->contentHandler, Chars, len); - SysFreeString(Chars); + while(This->lastCur < chEnd) + { + end = This->lastCur; + while(end < chEnd-1) + { + if(*end == '\r') break; + end++; + } - if(hr != S_OK) - format_error_message_from_id(This, hr); - } + Chars = bstr_from_xmlChar(This->lastCur); - update_position(This, NULL); + if(*end == '\r' && *(end+1) == '\n') + { + memmove((WCHAR*)Chars+(end-This->lastCur), + (WCHAR*)Chars+(end-This->lastCur)+1, + (SysStringLen(Chars)-(end-This->lastCur))*sizeof(WCHAR)); + SysReAllocStringLen(&Chars, Chars, SysStringLen(Chars)-1); + } + else if(*end == '\r') Chars[end-This->lastCur] = '\n'; + + hr = ISAXContentHandler_characters(This->saxreader->contentHandler, Chars, end-This->lastCur+1); + SysFreeString(Chars); + if(hr != S_OK) + { + format_error_message_from_id(This, hr); + return; + } + + if(*(end+1) == '\n') end++; + if(end < chEnd) end++; + + This->column += end-This->lastCur; + This->lastCur = end; + } + + This->lastCur = lastCurCopy; + This->column = columnCopy; + This->line = lineCopy; + update_position(This, chEnd); + } } static void libxmlSetDocumentLocator( -- 2.11.4.GIT