msxml3: Change ISAXXMLReader_getLine and ISAXXMLReader_getColumn functions.

This commit is contained in:
Piotr Caban 2008-07-23 16:39:04 +02:00 committed by Alexandre Julliard
parent fc825af3ee
commit bb849dc9c3
1 changed files with 52 additions and 32 deletions

View File

@ -64,8 +64,9 @@ typedef struct _saxlocator
xmlParserCtxtPtr pParserCtxt; xmlParserCtxtPtr pParserCtxt;
WCHAR *publicId; WCHAR *publicId;
WCHAR *systemId; WCHAR *systemId;
int lastLine; xmlChar *lastCur;
int lastColumn; int line;
int column;
} saxlocator; } saxlocator;
static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface ) static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
@ -83,6 +84,7 @@ static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
return (saxlocator *)((char*)iface - FIELD_OFFSET(saxlocator, lpSAXLocatorVtbl)); return (saxlocator *)((char*)iface - FIELD_OFFSET(saxlocator, lpSAXLocatorVtbl));
} }
static void format_error_message_from_id(saxlocator *This, HRESULT hr) static void format_error_message_from_id(saxlocator *This, HRESULT hr)
{ {
xmlStopParser(This->pParserCtxt); xmlStopParser(This->pParserCtxt);
@ -103,6 +105,35 @@ static void format_error_message_from_id(saxlocator *This, HRESULT hr)
} }
} }
static void update_position(saxlocator *This, xmlChar *end)
{
if(This->lastCur == NULL)
{
This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
This->line = 1;
This->column = 1;
}
if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
while(This->lastCur < end)
{
if(*(This->lastCur) == '\n')
{
This->line++;
This->column = 1;
}
else if(*(This->lastCur) == '\r' && (This->lastCur==This->pParserCtxt->input->end || *(This->lastCur+1)!='\n'))
{
This->line++;
This->column = 1;
}
else This->column++;
This->lastCur++;
}
}
/*** LibXML callbacks ***/ /*** LibXML callbacks ***/
static void libxmlStartDocument(void *ctx) static void libxmlStartDocument(void *ctx)
{ {
@ -116,8 +147,7 @@ static void libxmlStartDocument(void *ctx)
format_error_message_from_id(This, hr); format_error_message_from_id(This, hr);
} }
This->lastColumn = xmlSAX2GetColumnNumber(This->pParserCtxt); update_position(This, NULL);
This->lastLine = xmlSAX2GetLineNumber(This->pParserCtxt);
} }
static void libxmlEndDocument(void *ctx) static void libxmlEndDocument(void *ctx)
@ -125,8 +155,8 @@ static void libxmlEndDocument(void *ctx)
saxlocator *This = ctx; saxlocator *This = ctx;
HRESULT hr; HRESULT hr;
This->lastColumn = 0; This->column = 0;
This->lastLine = 0; This->line = 0;
if(This->ret != S_OK) return; if(This->ret != S_OK) return;
@ -155,8 +185,7 @@ static void libxmlStartElementNS(
FIXME("Arguments processing not yet implemented.\n"); FIXME("Arguments processing not yet implemented.\n");
This->lastColumn = xmlSAX2GetColumnNumber(This->pParserCtxt)+1; update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
This->lastLine = xmlSAX2GetLineNumber(This->pParserCtxt);
if(This->saxreader->contentHandler) if(This->saxreader->contentHandler)
{ {
@ -189,9 +218,11 @@ static void libxmlEndElementNS(
BSTR NamespaceUri, LocalName, QName; BSTR NamespaceUri, LocalName, QName;
saxlocator *This = ctx; saxlocator *This = ctx;
HRESULT hr; HRESULT hr;
xmlChar *end;
This->lastColumn = xmlSAX2GetColumnNumber(This->pParserCtxt); end = This->lastCur;
This->lastLine = xmlSAX2GetLineNumber(This->pParserCtxt); while(*end != '<' && *(end+1) != '/') end++;
update_position(This, end+2);
if(This->saxreader->contentHandler) if(This->saxreader->contentHandler)
{ {
@ -221,28 +252,14 @@ static void libxmlCharacters(
{ {
BSTR Chars; BSTR Chars;
saxlocator *This = ctx; saxlocator *This = ctx;
const xmlChar *cur;
int pos;
HRESULT hr; HRESULT hr;
xmlChar *end;
This->lastColumn = 1; if(*(This->lastCur-1) != '>')
This->lastLine = xmlSAX2GetLineNumber(This->pParserCtxt);
cur = This->pParserCtxt->input->cur;
if(*cur != '<')
{ {
for(pos=0; pos<len; pos++) end = (xmlChar*)This->pParserCtxt->input->cur-len;
if(*(cur+pos) == '\n') This->lastLine--; update_position(This, end);
cur--;
} }
else
{
for(pos=0; pos<len; pos++)
if(*(cur-pos-1) == '\n') This->lastLine--;
cur = cur-len-1;
}
for(; *cur!='\n' && cur!=This->pParserCtxt->input->base; cur--)
This->lastColumn++;
if(This->saxreader->contentHandler) if(This->saxreader->contentHandler)
{ {
@ -253,6 +270,8 @@ static void libxmlCharacters(
if(hr != S_OK) if(hr != S_OK)
format_error_message_from_id(This, hr); format_error_message_from_id(This, hr);
} }
update_position(This, NULL);
} }
static void libxmlSetDocumentLocator( static void libxmlSetDocumentLocator(
@ -366,7 +385,7 @@ static HRESULT WINAPI isaxlocator_getColumnNumber(
{ {
saxlocator *This = impl_from_ISAXLocator( iface ); saxlocator *This = impl_from_ISAXLocator( iface );
*pnColumn = This->lastColumn; *pnColumn = This->column;
return S_OK; return S_OK;
} }
@ -376,7 +395,7 @@ static HRESULT WINAPI isaxlocator_getLineNumber(
{ {
saxlocator *This = impl_from_ISAXLocator( iface ); saxlocator *This = impl_from_ISAXLocator( iface );
*pnLine = This->lastLine; *pnLine = This->line;
return S_OK; return S_OK;
} }
@ -452,8 +471,9 @@ static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator)
locator->pParserCtxt = NULL; locator->pParserCtxt = NULL;
locator->publicId = NULL; locator->publicId = NULL;
locator->systemId = NULL; locator->systemId = NULL;
locator->lastLine = 0; locator->lastCur = NULL;
locator->lastColumn = 0; locator->line = 0;
locator->column = 0;
locator->ret = S_OK; locator->ret = S_OK;
*ppsaxlocator = locator; *ppsaxlocator = locator;