skip unknown elements when reading multiple elements from docx mathml
This commit is contained in:
parent
b0604113bc
commit
0acff1783a
3 changed files with 24 additions and 13 deletions
|
@ -104,7 +104,18 @@ while( !stream.atEnd() && stream.currentToken() != CLOSING( element ))
|
|||
stream.ensureClosingTag( element );
|
||||
@endcode
|
||||
|
||||
If there may be just a one type of sub-element, handle it directly without the switch statement.
|
||||
If there may not be a zero number of sub-elements, use a helper bool variable or use a do-while loop.
|
||||
|
||||
Parse an element that may contain an unknown number of sub-elements of the same type:
|
||||
@code
|
||||
stream.ensureOpeningTag( element );
|
||||
while( !stream.atEnd() && stream.findTag( OPENING( subelement )))
|
||||
{
|
||||
handleSubelement();
|
||||
}
|
||||
stream.ensureClosingTag( element );
|
||||
@endcode
|
||||
|
||||
If there may not be a zero number of sub-elements, use a helper bool variable or use a do-while loop.
|
||||
|
||||
@since 3.5
|
||||
|
@ -198,9 +209,9 @@ public:
|
|||
void ensureClosingTag( int token );
|
||||
/**
|
||||
Tries to find the given token, until either found (returns true) or end of current element.
|
||||
Position in the stream is set to make the tag current.
|
||||
Position in the stream is set to make the tag current (i.e. it will be the next one read).
|
||||
*/
|
||||
bool recoverAndFindTag( int token );
|
||||
bool findTag( int token );
|
||||
/**
|
||||
Skips the given element (i.e. reads up to and including the matching closing tag).
|
||||
*/
|
||||
|
@ -211,7 +222,7 @@ public:
|
|||
void handleUnexpectedTag();
|
||||
protected:
|
||||
Tag checkTag( int token, bool optional );
|
||||
bool recoverAndFindTagInternal( int token, bool silent );
|
||||
bool findTagInternal( int token, bool silent );
|
||||
void skipElementInternal( int token, bool silent );
|
||||
std::vector< Tag > tags;
|
||||
unsigned int pos;
|
||||
|
|
|
@ -233,14 +233,14 @@ XmlStream::Tag XmlStream::checkTag( int token, bool optional )
|
|||
if( optional )
|
||||
{ // avoid printing debug messages about skipping tags if the optional one
|
||||
// will not be found and the position will be reset back
|
||||
if( currentToken() != token && !recoverAndFindTagInternal( token, true ))
|
||||
if( currentToken() != token && !findTagInternal( token, true ))
|
||||
{
|
||||
pos = savedPos;
|
||||
return Tag();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if( currentToken() == token || recoverAndFindTag( token ))
|
||||
if( currentToken() == token || findTag( token ))
|
||||
{
|
||||
Tag ret = currentTag();
|
||||
moveToNextTag();
|
||||
|
@ -255,12 +255,12 @@ XmlStream::Tag XmlStream::checkTag( int token, bool optional )
|
|||
return Tag();
|
||||
}
|
||||
|
||||
bool XmlStream::recoverAndFindTag( int token )
|
||||
bool XmlStream::findTag( int token )
|
||||
{
|
||||
return recoverAndFindTagInternal( token, false );
|
||||
return findTagInternal( token, false );
|
||||
}
|
||||
|
||||
bool XmlStream::recoverAndFindTagInternal( int token, bool /*silent*/ )
|
||||
bool XmlStream::findTagInternal( int token, bool /*silent*/ )
|
||||
{
|
||||
int depth = 0;
|
||||
for(;
|
||||
|
@ -320,7 +320,7 @@ void XmlStream::skipElementInternal( int token, bool /*silent*/ )
|
|||
// fprintf( stderr, "Skipping unexpected element %s\n", CSTR( tokenToString( currentToken())));
|
||||
moveToNextTag();
|
||||
// and just find the matching closing tag
|
||||
if( recoverAndFindTag( closing ))
|
||||
if( findTag( closing ))
|
||||
{
|
||||
// if( !silent )
|
||||
// fprintf( stderr, "Skipped unexpected element %s\n", CSTR( tokenToString( token )));
|
||||
|
|
|
@ -346,7 +346,7 @@ OUString SmOoxmlImport::handleD()
|
|||
OUStringBuffer ret;
|
||||
ret.append( opening );
|
||||
bool first = true;
|
||||
while( stream.currentToken() == OPENING( M_TOKEN( e )))
|
||||
while( stream.findTag( OPENING( M_TOKEN( e ))))
|
||||
{
|
||||
if( !first )
|
||||
ret.append( separator );
|
||||
|
@ -464,12 +464,12 @@ OUString SmOoxmlImport::handleM()
|
|||
if( !row.isEmpty())
|
||||
row += STR( " # " );
|
||||
row += readOMathArgInElement( M_TOKEN( e ));
|
||||
} while( !stream.atEnd() && stream.currentToken() == OPENING( M_TOKEN( e )));
|
||||
} while( !stream.atEnd() && stream.findTag( OPENING( M_TOKEN( e ))));
|
||||
if( !allrows.isEmpty())
|
||||
allrows += STR( " ## " );
|
||||
allrows += row;
|
||||
stream.ensureClosingTag( M_TOKEN( mr ));
|
||||
} while( !stream.atEnd() && stream.currentToken() == OPENING( M_TOKEN( mr )));
|
||||
} while( !stream.atEnd() && stream.findTag( OPENING( M_TOKEN( mr ))));
|
||||
stream.ensureClosingTag( M_TOKEN( m ));
|
||||
return STR( "matrix {" ) + allrows + STR( "}" );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue