1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/xmlobj.cpp Mon Jan 14 16:27:00 2008 +0000
1.3 @@ -0,0 +1,94 @@
1.4 +#include "xmlobj.h"
1.5 +
1.6 +#include <QRegExp>
1.7 +
1.8 +
1.9 +// returns masked "<" ">" "&"
1.10 +QString quotemeta(const QString &s)
1.11 +{
1.12 + QString r=s;
1.13 + QRegExp rx("&(?!amp;)");
1.14 + r.replace ( rx,"&");
1.15 + rx.setPattern( ">");
1.16 + r.replace ( rx,">");
1.17 + rx.setPattern( "<");
1.18 + r.replace ( rx,"<");
1.19 + rx.setPattern( "\"");
1.20 + r.replace ( rx,""");
1.21 + return r;
1.22 +}
1.23 +
1.24 +
1.25 +
1.26 +int XMLObj::actindent=0; // make instance of actindent
1.27 +
1.28 +XMLObj::XMLObj()
1.29 +{
1.30 + indentwidth=4;
1.31 +}
1.32 +
1.33 +
1.34 +// returns <s at />
1.35 +QString XMLObj::singleElement(QString s, QString at)
1.36 +{
1.37 + return indent() + "<" + s +" " + at +" " + "/>\n";
1.38 +}
1.39 +
1.40 +// returns <s>
1.41 +QString XMLObj::beginElement(QString s)
1.42 +{
1.43 + return indent() + "<" + s + ">\n";
1.44 +}
1.45 +
1.46 +// returns <s at>
1.47 +QString XMLObj::beginElement(QString s, QString at)
1.48 +{
1.49 + return indent() + "<" + s + " " + at + ">\n";
1.50 +}
1.51 +
1.52 +// returns </s>
1.53 +QString XMLObj::endElement(QString s)
1.54 +{
1.55 + return indent() + "</" + s + ">\n";
1.56 +}
1.57 +
1.58 +// returns at="val"
1.59 +QString XMLObj::attribut(QString at, QString val)
1.60 +{
1.61 + return " " + at + "=\"" + quotemeta (val) + "\"";
1.62 +}
1.63 +
1.64 +// returns <s> val </s>
1.65 +QString XMLObj::valueElement(QString el, QString val)
1.66 +{
1.67 + return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
1.68 +}
1.69 +
1.70 +// returns <s at> val </s>
1.71 +QString XMLObj::valueElement(QString el, QString val, QString at)
1.72 +{
1.73 + return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
1.74 +}
1.75 +
1.76 +void XMLObj::incIndent()
1.77 +{
1.78 + actindent++;
1.79 +}
1.80 +
1.81 +void XMLObj::decIndent()
1.82 +{
1.83 + actindent--;
1.84 + if (actindent<0) actindent=0;
1.85 +}
1.86 +
1.87 +QString XMLObj::indent()
1.88 +{
1.89 + QString s;
1.90 + int i;
1.91 + for (i=0; i<actindent*indentwidth; i++)
1.92 + {
1.93 + s= s + " ";
1.94 + }
1.95 + return s;
1.96 +}
1.97 +