From f92bb660961a3f2dee392eac214bdd568ba2ea52 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Tue, 29 Nov 2011 19:17:35 +0100 Subject: no debug about skipping tags if not actually skipping --- oox/inc/oox/mathml/importutils.hxx | 1 + oox/source/mathml/importutils.cxx | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) (limited to 'oox') diff --git a/oox/inc/oox/mathml/importutils.hxx b/oox/inc/oox/mathml/importutils.hxx index a90028dadbcd..68f6a0ab8155 100644 --- a/oox/inc/oox/mathml/importutils.hxx +++ b/oox/inc/oox/mathml/importutils.hxx @@ -163,6 +163,7 @@ public: void handleUnexpectedTag(); protected: Tag checkTag( int token, bool optional ); + bool recoverAndFindTagHelper( int token, bool silent ); std::vector< Tag > tags; unsigned int pos; }; diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx index 3a21bad8f89c..703e96b8752d 100644 --- a/oox/source/mathml/importutils.cxx +++ b/oox/source/mathml/importutils.cxx @@ -42,6 +42,11 @@ #define CSTR( str ) ( rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr()) +// HACK - TODO convert to the real debug stuff +#undef SAL_LOG_LEVEL +#define SAL_LOG_LEVEL 2 + + using namespace com::sun::star; using rtl::OUString; @@ -220,6 +225,17 @@ XmlStream::Tag XmlStream::checkTag( int token, bool optional ) { // either it's the following tag, or find it int savedPos = pos; +#if SAL_LOG_LEVEL >= 2 + 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 && !recoverAndFindTagHelper( token, true )) + { + pos = savedPos; + return Tag(); + } + } +#endif if( currentToken() == token || recoverAndFindTag( token )) { Tag ret = currentTag(); @@ -236,6 +252,11 @@ XmlStream::Tag XmlStream::checkTag( int token, bool optional ) } bool XmlStream::recoverAndFindTag( int token ) +{ + return recoverAndFindTagHelper( token, false ); +} + +bool XmlStream::recoverAndFindTagHelper( int token, bool silent ) { int depth = 0; for(; @@ -246,17 +267,20 @@ bool XmlStream::recoverAndFindTag( int token ) { if( currentToken() == OPENING( currentToken())) { - fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken()))); + if( !silent ) + fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken()))); ++depth; } else if( currentToken() == CLOSING( currentToken())) - { // TODO debug output without the OPENING/CLOSING bits set - fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken()))); + { + if( !silent ) + fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken()))); --depth; } else { - fprintf( stderr, "Malformed token %d (%s)\n", currentToken(), CSTR( tokenToString( currentToken()))); + if( !silent ) + fprintf( stderr, "Malformed token %d (%s)\n", currentToken(), CSTR( tokenToString( currentToken()))); abort(); } continue; @@ -267,13 +291,15 @@ bool XmlStream::recoverAndFindTag( int token ) return false; // that would be leaving current element, so not found if( currentToken() == OPENING( currentToken())) { - fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken()))); + if( !silent ) + fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken()))); ++depth; } else abort(); } - fprintf( stderr, "Unexpected end of stream reached.\n" ); + if( !silent ) + fprintf( stderr, "Unexpected end of stream reached.\n" ); return false; } -- cgit