diff -r 000000000000 -r d4b49c6c6069 xmlobj.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xmlobj.cpp Wed Jan 16 15:45:19 2008 +0000 @@ -0,0 +1,94 @@ +#include "xmlobj.h" + +#include + + +// returns masked "<" ">" "&" +QString quotemeta(const QString &s) +{ + QString r=s; + QRegExp rx("&(?!amp;)"); + r.replace ( rx,"&"); + rx.setPattern( ">"); + r.replace ( rx,">"); + rx.setPattern( "<"); + r.replace ( rx,"<"); + rx.setPattern( "\""); + r.replace ( rx,"""); + return r; +} + + + +int XMLObj::actindent=0; // make instance of actindent + +XMLObj::XMLObj() +{ + indentwidth=4; +} + + +// returns +QString XMLObj::singleElement(QString s, QString at) +{ + return indent() + "<" + s +" " + at +" " + "/>\n"; +} + +// returns +QString XMLObj::beginElement(QString s) +{ + return indent() + "<" + s + ">\n"; +} + +// returns +QString XMLObj::beginElement(QString s, QString at) +{ + return indent() + "<" + s + " " + at + ">\n"; +} + +// returns +QString XMLObj::endElement(QString s) +{ + return indent() + "\n"; +} + +// returns at="val" +QString XMLObj::attribut(QString at, QString val) +{ + return " " + at + "=\"" + quotemeta (val) + "\""; +} + +// returns val +QString XMLObj::valueElement(QString el, QString val) +{ + return indent() + "<" + el + ">" + quotemeta(val) + "\n"; +} + +// returns val +QString XMLObj::valueElement(QString el, QString val, QString at) +{ + return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "\n"; +} + +void XMLObj::incIndent() +{ + actindent++; +} + +void XMLObj::decIndent() +{ + actindent--; + if (actindent<0) actindent=0; +} + +QString XMLObj::indent() +{ + QString s; + int i; + for (i=0; i