From: Konrad Rosenbaum Date: Mon, 30 Jan 2012 21:07:21 +0000 (+0100) Subject: converter routine for odf templates X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=229f028766216f54be025830c8a1d542974ec37e;p=web%2Fkonrad%2Fsmoke.git converter routine for odf templates --- diff --git a/src/misc/misc.cpp b/src/misc/misc.cpp index f2c0f98..663d788 100644 --- a/src/misc/misc.cpp +++ b/src/misc/misc.cpp @@ -52,6 +52,21 @@ QString xmlize(QString str,QString newline) } return out; } +QByteArray xmlize(QByteArray str,QString newline) +{ + QByteArray out; + for(int i=0;i')out+=">";else + if(c=='&')out+="&";else + if(c=='\n')out+=newline;else + if(QChar(c).isSpace()||(c>=32&&c<=0x7f))out+=c; + else out+="&#"+QString::number((unsigned char)c)+";"; + } + return out; +} + QString cent2str(qint64 c,bool localize) { MLocalFormat mf; diff --git a/src/misc/misc.h b/src/misc/misc.h index 156b37c..4511d30 100644 --- a/src/misc/misc.h +++ b/src/misc/misc.h @@ -26,6 +26,8 @@ QString htmlize(QString str); /**converts special XML characters into harmless &-codes, so the text can be included*/ QString xmlize(QString str,QString newline="\n"); +/**converts special XML characters into harmless &-codes, so the text can be included*/ +QByteArray xmlize(QByteArray str,QString newline="\n"); /**converts a cent value into a (localized) string*/ QString cent2str(qint64 cent,bool localize=true); diff --git a/src/templates/odtrender.cpp b/src/templates/odtrender.cpp index 655df4c..7938cf2 100644 --- a/src/templates/odtrender.cpp +++ b/src/templates/odtrender.cpp @@ -117,13 +117,13 @@ MOdtRendererPrivate::MOdtRendererPrivate(QString file,MOdtRenderer*p) } //conversion process if(!dov1)return; - buffer.setData(MOdtRenderer::convertV1toV2(buffer.data())); //try again - if(!cdoc.setContent(&buffer,true,&err,&errln,&errcl)){ + if(!cdoc.setContent(MOdtRenderer::convertV1toV2(buffer.data()),true,&err,&errln,&errcl)){ qDebug()<<"Hmm, definitely not XML - even after conversion, aborting..."; qDebug()<<" Info: line ="<olst=old.split('\n'); - foreach(const QByteArray&line,olst){ - nba+=line; + bool hstarted=false; + foreach(QByteArray line,olst){ + //is this the start of the file? + if(!hstarted){ + QByteArray st=line.trimmed().left(2); + //find the first real tag and insert the new start tag there + if(st!="\n"; + hstarted=true; + } + //add the line just scanned... + nba+=line; + nba+='\n'; + continue; + } + //is this a special line? + QByteArray lnt=line.trimmed(); + if(lnt.size()>1 && lnt.at(0)=='#'){ + //extract command + int cnt=lnt.indexOf(':'); + QByteArray parm; + if(cnt>0){ + parm=lnt.mid(cnt+1); + lnt=lnt.left(cnt); +// qDebug()<<"found command"<"; + }else if(lnt=="#ELSE") + nba+=""; + else if(lnt=="#ENDIF") + nba+=""; + else if(lnt=="#SETNEWLINE"){ + nba+=""; + }else if(lnt=="#CALC"){ + nba+=""; + }else if(lnt=="#LOOP"){ + nba+=""; + }else if(lnt=="#ENDLOOP"){ + nba+=""; + }else{ + nba+=""; + } + }else //no, not special: just store it + nba+=line; + //add a newline anyway nba+='\n'; } - qDebug()<<"conversion test"<