1.11.2 split up of xml helper functions. started to work on attributes
authorinsilmaril
Thu Nov 08 15:28:03 2007 +0000 (2007-11-08)
changeset 621c60984c46f9f
parent 620 24bfecc949a0
child 622 9f739222ee8c
1.11.2 split up of xml helper functions. started to work on attributes
xlinkobj.h
xmlobj.cpp
xmlobj.h
     1.1 --- a/xlinkobj.h	Thu Nov 08 15:28:03 2007 +0000
     1.2 +++ b/xlinkobj.h	Thu Nov 08 15:28:03 2007 +0000
     1.3 @@ -3,6 +3,8 @@
     1.4  
     1.5  #include "linkablemapobj.h"
     1.6  
     1.7 +class BranchObj;
     1.8 +
     1.9  enum XLinkState {undefinedXLink,initXLink,activeXLink,deleteXLink};
    1.10  
    1.11  /*! \brief xlinks are used to draw arbitrary connections between branches (BranchObj) in the map. */
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/xmlobj.cpp	Thu Nov 08 15:28:03 2007 +0000
     2.3 @@ -0,0 +1,94 @@
     2.4 +#include "xmlobj.h"
     2.5 +
     2.6 +#include <QRegExp>
     2.7 +
     2.8 +
     2.9 +// returns masked "<" ">" "&"
    2.10 +QString quotemeta(const QString &s)
    2.11 +{
    2.12 +	QString r=s;
    2.13 +    QRegExp  rx("&(?!amp;)");
    2.14 +    r.replace ( rx,"&amp;");
    2.15 +    rx.setPattern( ">");
    2.16 +    r.replace ( rx,"&gt;");
    2.17 +    rx.setPattern( "<");
    2.18 +    r.replace ( rx,"&lt;");
    2.19 +    rx.setPattern( "\"");
    2.20 +    r.replace ( rx,"&quot;");
    2.21 +    return r;
    2.22 +}
    2.23 +
    2.24 +
    2.25 +
    2.26 +int XMLObj::actindent=0;		// make instance of actindent
    2.27 +
    2.28 +XMLObj::XMLObj()
    2.29 +{
    2.30 +    indentwidth=4;
    2.31 +}
    2.32 +
    2.33 +
    2.34 +// returns <s at />
    2.35 +QString XMLObj::singleElement(QString s, QString at)
    2.36 +{
    2.37 +    return indent() + "<" + s +" " + at +" " + "/>\n";
    2.38 +}
    2.39 +
    2.40 +// returns <s>
    2.41 +QString XMLObj::beginElement(QString s)
    2.42 +{
    2.43 +    return indent() + "<" + s + ">\n";
    2.44 +}
    2.45 +
    2.46 +// returns <s at>
    2.47 +QString XMLObj::beginElement(QString s, QString at)
    2.48 +{
    2.49 +    return indent() + "<" + s + " " + at + ">\n";
    2.50 +}
    2.51 +
    2.52 +// returns </s>
    2.53 +QString XMLObj::endElement(QString s)
    2.54 +{
    2.55 +    return indent() + "</" + s + ">\n";
    2.56 +}
    2.57 +
    2.58 +// returns  at="val"
    2.59 +QString XMLObj::attribut(QString at, QString val)
    2.60 +{
    2.61 +    return " " + at + "=\"" + quotemeta (val) + "\""; 
    2.62 +}
    2.63 +
    2.64 +// returns <s> val </s>
    2.65 +QString XMLObj::valueElement(QString el, QString val)
    2.66 +{
    2.67 +    return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
    2.68 +}
    2.69 +
    2.70 +// returns <s at> val </s>
    2.71 +QString XMLObj::valueElement(QString el, QString val, QString at)
    2.72 +{
    2.73 +    return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
    2.74 +}
    2.75 +
    2.76 +void XMLObj::incIndent()
    2.77 +{
    2.78 +    actindent++;
    2.79 +}	
    2.80 +
    2.81 +void XMLObj::decIndent()
    2.82 +{
    2.83 +    actindent--;
    2.84 +    if (actindent<0) actindent=0;
    2.85 +}	
    2.86 +
    2.87 +QString XMLObj::indent()
    2.88 +{
    2.89 +    QString s;
    2.90 +    int i;
    2.91 +    for (i=0; i<actindent*indentwidth; i++)
    2.92 +    {
    2.93 +		s= s + " ";
    2.94 +    }
    2.95 +    return s;
    2.96 +}	
    2.97 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/xmlobj.h	Thu Nov 08 15:28:03 2007 +0000
     3.3 @@ -0,0 +1,29 @@
     3.4 +#ifndef XMLOBJ_H
     3.5 +#define XMLOBJ_H
     3.6 +
     3.7 +#include <QString>
     3.8 +
     3.9 +QString quotemeta(const QString&);	
    3.10 +
    3.11 +/////////////////////////////////////////////////////////////////////////////
    3.12 +class XMLObj
    3.13 +{
    3.14 +public:
    3.15 +    XMLObj();
    3.16 +    QString singleElement(QString,QString);			// name,attr
    3.17 +    QString beginElement(QString,QString);			// name,attr
    3.18 +    QString beginElement(QString);					// name
    3.19 +    QString endElement  (QString);					// name
    3.20 +    QString attribut    (QString,QString);			// name, val
    3.21 +    QString valueElement(QString,QString);			// name, val
    3.22 +    QString valueElement(QString,QString,QString);	// name, attr, val
    3.23 +    void incIndent();
    3.24 +    void decIndent();
    3.25 +    static int actindent;
    3.26 +
    3.27 +protected:  
    3.28 +    QString indent();
    3.29 +    int indentwidth;
    3.30 +};
    3.31 +
    3.32 +#endif