diff options
Diffstat (limited to 'hwpfilter/source/formula.cxx')
-rw-r--r-- | hwpfilter/source/formula.cxx | 108 |
1 files changed, 53 insertions, 55 deletions
diff --git a/hwpfilter/source/formula.cxx b/hwpfilter/source/formula.cxx index f9ab4566668f..e220afe9d881 100644 --- a/hwpfilter/source/formula.cxx +++ b/hwpfilter/source/formula.cxx @@ -20,13 +20,12 @@ #include "formula.h" #include "grammar.hxx" -#include "mzstring.h" #include "nodes.h" #include "mapping.h" #include "hwpeq.h" #include <iostream> -#ifndef DEBUG +#if OSL_DEBUG_LEVEL < 2 #include "hcode.h" @@ -47,7 +46,7 @@ void Formula::makeMathML(Node *res) { Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:math xmlns:math=\"http://www.w3.org/1998/Math/MathML\">\n"); #else @@ -59,7 +58,7 @@ void Formula::makeMathML(Node *res) if( tmp->child ) makeLines( tmp->child ); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:semantics/>\n"); indo; @@ -89,14 +88,14 @@ void Formula::makeLines(Node *res) void Formula::makeLine(Node *res) { if( !res ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); #else rstartEl("math:mrow", mxList); #endif if( res->child ) makeExprList( res->child ); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); #else rendEl("math:mrow"); @@ -127,7 +126,7 @@ void Formula::makeExpr(Node *res) switch( tmp->id ) { case ID_PRIMARYEXPR: if( tmp->next ){ -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); #else @@ -138,7 +137,7 @@ void Formula::makeExpr(Node *res) makePrimary(tmp); if( tmp->next ){ -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); #else rendEl("math:mrow"); @@ -189,57 +188,57 @@ void Formula::makeIdentifier(Node *res) if( !tmp->value ) return; switch( tmp->id ){ case ID_CHARACTER : -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; - fprintf(stderr,"<math:mi>%s</math:mi>\n",tmp->value); + fprintf(stderr,"<math:mi>%s</math:mi>\n",tmp->value.get()); indo; #else rstartEl("math:mi", mxList); - rchars(OUString::createFromAscii(tmp->value)); + rchars(OUString::createFromAscii(tmp->value.get())); rendEl("math:mi"); #endif break; case ID_STRING : { -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 #else rstartEl("math:mi", mxList); - reucstr(tmp->value, strlen(tmp->value)); + reucstr(tmp->value.get(), strlen(tmp->value.get())); rendEl("math:mi"); #endif } break; case ID_IDENTIFIER : -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mi>%s</math:mi>\n", - getMathMLEntity(tmp->value).c_str()); + getMathMLEntity(tmp->value.get()).c_str()); indo; #else rstartEl("math:mi", mxList); - runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value))); + runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get()))); rendEl("math:mi"); #endif break; case ID_NUMBER : -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; - fprintf(stderr,"<math:mn>%s</math:mn>\n",tmp->value); + fprintf(stderr,"<math:mn>%s</math:mn>\n",tmp->value.get()); indo; #else rstartEl("math:mn", mxList); - rchars(OUString::createFromAscii(tmp->value)); + rchars(OUString::createFromAscii(tmp->value.get())); rendEl("math:mn"); #endif break; case ID_OPERATOR : case ID_DELIMITER : { -#ifdef DEBUG - inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value); indo; +#if OSL_DEBUG_LEVEL >= 2 + inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value.get()); indo; #else rstartEl("math:mo", mxList); - runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value))); + runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get()))); rendEl("math:mo"); #endif break; @@ -268,7 +267,7 @@ void Formula::makeSubSup(Node *res) Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; if( res->id == ID_SUBEXPR ) fprintf(stderr,"<math:msub>\n"); @@ -296,7 +295,7 @@ void Formula::makeSubSup(Node *res) makeExpr(tmp->next); } -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; if( res->id == ID_SUBEXPR ) fprintf(stderr,"</math:msub>\n"); @@ -319,7 +318,7 @@ void Formula::makeFraction(Node *res) Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mfrac>\n"); #else @@ -327,7 +326,7 @@ void Formula::makeFraction(Node *res) #endif tmp = tmp->child; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); #else @@ -339,7 +338,7 @@ void Formula::makeFraction(Node *res) else makeExprList(tmp); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); inds; @@ -354,7 +353,7 @@ void Formula::makeFraction(Node *res) else makeExprList(tmp->next); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); inde; @@ -370,9 +369,9 @@ void Formula::makeDecoration(Node *res) int isover = 1; Node *tmp = res->child; if( !tmp ) return; - if( !strncmp(tmp->value,"under", 5) ) + if( !strncmp(tmp->value.get(),"under", 5) ) isover = 0; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; if( isover ) fprintf(stderr,"<math:mover>\n"); @@ -393,18 +392,18 @@ void Formula::makeDecoration(Node *res) makeBlock(tmp->next); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mo>%s</math:mo>\n", - getMathMLEntity(tmp->value).c_str()); + getMathMLEntity(tmp->value.get()).c_str()); indo; #else rstartEl("math:mo", mxList); - runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value))); + runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get()))); rendEl("math:mo"); #endif -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; if( isover ) fprintf(stderr,"</math:mover>\n"); @@ -422,7 +421,7 @@ void Formula::makeRoot(Node *res) { Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; if( tmp->id == ID_SQRTEXPR ) fprintf(stderr,"<math:msqrt>\n"); @@ -443,7 +442,7 @@ void Formula::makeRoot(Node *res) makeBlock(tmp->child->next); } -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; if( tmp->id == ID_SQRTEXPR ) fprintf(stderr,"</math:msqrt>\n"); @@ -464,7 +463,7 @@ void Formula::makeParenth(Node *res) { Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); inds; @@ -489,7 +488,7 @@ void Formula::makeParenth(Node *res) if( tmp->child ) makeExprList(tmp->child); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); inds; @@ -515,23 +514,23 @@ void Formula::makeParenth(Node *res) void Formula::makeFence(Node *res) { Node *tmp = res->child; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mfenced open=\"%s\" close=\"%s\">\n", - getMathMLEntity(tmp->value).c_str(), - getMathMLEntity(tmp->next->next->value).c_str()); + getMathMLEntity(tmp->value.get()).c_str(), + getMathMLEntity(tmp->next->next->value.get()).c_str()); #else padd("open", "CDATA", - OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str()))); + OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value.get()).c_str()))); padd("close", "CDATA", - OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->next->next->value).c_str()))); + OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->next->next->value.get()).c_str()))); rstartEl("math:mfenced", mxList); mxList->clear(); #endif makeExprList(tmp->next); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mfenced>\n"); #else @@ -546,7 +545,7 @@ void Formula::makeBracket(Node *res) void Formula::makeBlock(Node *res) { -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); #else @@ -556,7 +555,7 @@ void Formula::makeBlock(Node *res) if( res->child ) makeExprList(res->child); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); #else @@ -569,22 +568,21 @@ void Formula::parse() Node *res = nullptr; if( !eq ) return; - MzString a; + OString a; // fprintf(stderr,"\n\n[BEFORE]\n[%s]\n",eq); eq2latex(a,eq); - int idx=a.find(sal::static_int_cast<char>(0xff)); - while(idx){ + int idx=a.indexOf('\xff'); + while(idx >= 0){ //printf("idx = [%d]\n",idx); - a.replace(idx,0x20); - if((idx = a.find(sal::static_int_cast<char>(0xff),idx+1)) < 0) - break; + a = a.replaceAt(idx, 1, "\x20"); + idx = a.indexOf('\xff', idx + 1); } - char *buf = static_cast<char *>(malloc(a.length()+1)); + char *buf = static_cast<char *>(malloc(a.getLength()+1)); bool bStart = false; int i, j; - for( i = 0, j=0 ; i < a.length() ; i++){ // rtrim and ltrim 32 10 13 + for( i = 0, j=0 ; i < a.getLength() ; i++){ // rtrim and ltrim 32 10 13 if( bStart ){ buf[j++] = a[i]; } @@ -605,7 +603,7 @@ void Formula::parse() } // fprintf(stderr,"\n\n[RESULT]\n[%s]\n",a.c_str()); if( buf[0] != '\0' ) - res = mainParse( a.c_str() ); + res = mainParse( a.getStr() ); else res = nullptr; free(buf); |