diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2011-11-29 19:05:52 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2011-11-29 21:20:27 +0100 |
commit | 6bbca34846fd9e2d26d035dc7255bb3d77e2869b (patch) | |
tree | 43bbbb9786e8df0bd7033b251e6810bba82632e9 /oox/source/mathml | |
parent | eb31865c852ac1843ab6060fdc401cf5cc2bf13c (diff) |
make debug output print tags as strings rather than id numbers
Diffstat (limited to 'oox/source/mathml')
-rw-r--r-- | oox/source/mathml/importutils.cxx | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx index 69fa1fc14f02..3a21bad8f89c 100644 --- a/oox/source/mathml/importutils.cxx +++ b/oox/source/mathml/importutils.cxx @@ -31,10 +31,19 @@ #include <assert.h> #include <stdio.h> +#include <oox/token/namespacemap.hxx> +#include <oox/token/tokenmap.hxx> #include <oox/token/tokens.hxx> #include <oox/token/namespaces.hxx> +#include <rtl/string.hxx> + +// *sigh* +#define STR( str ) OUString( RTL_CONSTASCII_USTRINGPARAM( str )) +#define CSTR( str ) ( rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr()) + using namespace com::sun::star; +using rtl::OUString; namespace oox { @@ -67,6 +76,40 @@ AttributeListBuilder::AttributeListBuilder( const uno::Reference< xml::sax::XFas attrs[ pFastAttr[ i ].Token ] = pFastAttr[ i ].Value; } } + +static OUString tokenToString( int token ) +{ + OUString tokenname = StaticTokenMap::get().getUnicodeTokenName( token & TOKEN_MASK ); + if( tokenname.isEmpty()) + tokenname = STR( "???" ); + int nmsp = ( token & NMSP_MASK & ~( TAG_OPENING | TAG_CLOSING )); +#if 0 // this is awfully long + OUString namespacename = StaticNamespaceMap::get().count( nmsp ) != 0 + ? StaticNamespaceMap::get()[ nmsp ] : STR( "???" ); +#else + OUString namespacename; + // only few are needed actually + switch( nmsp ) + { + case NMSP_officeMath: + namespacename = STR( "m" ); + break; + case NMSP_doc: + namespacename = STR( "w" ); + break; + default: + namespacename = STR( "?" ); + break; + } +#endif + if( token == OPENING( token )) + return STR( "<" ) + namespacename + STR( ":" ) + tokenname + STR ( ">" ); + if( token == CLOSING( token )) + return STR( "</" ) + namespacename + STR( ":" ) + tokenname + STR ( ">" ); + // just the name itself, not specified whether opening or closing + return namespacename + STR( ":" ) + tokenname; +} + } // namespace bool XmlStream::AttributeList::hasAttribute( int token ) const @@ -93,8 +136,7 @@ bool XmlStream::AttributeList::attribute( int token, bool def ) const if( find->second.equalsIgnoreAsciiCaseAscii( "false" ) || find->second.equalsIgnoreAsciiCaseAscii( "off" ) || find->second.equalsIgnoreAsciiCaseAscii( "f" ) || find->second.equalsIgnoreAsciiCaseAscii( "0" )) return false; - fprintf( stderr, "Cannot convert \'%s\' to bool.\n", - rtl::OUStringToOString( find->second, RTL_TEXTENCODING_UTF8 ).getStr()); + fprintf( stderr, "Cannot convert \'%s\' to bool.\n", CSTR( find->second )); } return def; } @@ -107,8 +149,7 @@ sal_Unicode XmlStream::AttributeList::attribute( int token, sal_Unicode def ) co if( find->second.getLength() >= 1 ) { if( find->second.getLength() != 1 ) - fprintf( stderr, "Cannot convert \'%s\' to sal_Unicode, stripping.\n", - rtl::OUStringToOString( find->second, RTL_TEXTENCODING_UTF8 ).getStr()); + fprintf( stderr, "Cannot convert \'%s\' to sal_Unicode, stripping.\n", CSTR( find->second )); return find->second[ 0 ]; } } @@ -162,20 +203,20 @@ void XmlStream::moveToNextTag() XmlStream::Tag XmlStream::ensureOpeningTag( int token ) { - return checkTag( OPENING( token ), false, "opening" ); + return checkTag( OPENING( token ), false ); } XmlStream::Tag XmlStream::checkOpeningTag( int token ) { - return checkTag( OPENING( token ), true, "opening" ); + return checkTag( OPENING( token ), true ); } void XmlStream::ensureClosingTag( int token ) { - checkTag( CLOSING( token ), false, "closing" ); + checkTag( CLOSING( token ), false ); } -XmlStream::Tag XmlStream::checkTag( int token, bool optional, const char* txt ) +XmlStream::Tag XmlStream::checkTag( int token, bool optional ) { // either it's the following tag, or find it int savedPos = pos; @@ -190,7 +231,7 @@ XmlStream::Tag XmlStream::checkTag( int token, bool optional, const char* txt ) pos = savedPos; return Tag(); } - fprintf( stderr, "Expected %s tag %d not found.\n", txt, token ); + fprintf( stderr, "Expected tag %s not found.\n", CSTR( tokenToString( token ))); return Tag(); } @@ -205,17 +246,17 @@ bool XmlStream::recoverAndFindTag( int token ) { if( currentToken() == OPENING( currentToken())) { - fprintf( stderr, "Skipping opening tag %d\n", currentToken()); + 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 closing tag %d\n", currentToken()); + fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken()))); --depth; } else { - fprintf( stderr, "Malformed token %d\n", currentToken()); + fprintf( stderr, "Malformed token %d (%s)\n", currentToken(), CSTR( tokenToString( currentToken()))); abort(); } continue; @@ -226,7 +267,7 @@ bool XmlStream::recoverAndFindTag( int token ) return false; // that would be leaving current element, so not found if( currentToken() == OPENING( currentToken())) { - fprintf( stderr, "Skipping opening tag %d\n", currentToken()); + fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken()))); ++depth; } else @@ -247,7 +288,7 @@ void XmlStream::skipElement( int token ) moveToNextTag(); // and skip it too return; } - fprintf( stderr, "Expected end of element %d not found.\n", token ); + fprintf( stderr, "Expected end of element %s not found.\n", CSTR( tokenToString( token ))); } void XmlStream::handleUnexpectedTag() |