xmlobj.cpp
author insilmaril
Mon, 15 Mar 2010 15:32:37 +0000
changeset 836 62d621e3e550
parent 791 f1006de05c54
child 847 43268373032d
permissions -rw-r--r--
Fix for animation of branches using relPos
insilmaril@621
     1
#include "xmlobj.h"
insilmaril@621
     2
insilmaril@621
     3
#include <QRegExp>
insilmaril@721
     4
#include <QString>
insilmaril@621
     5
insilmaril@621
     6
insilmaril@621
     7
// returns masked "<" ">" "&"
insilmaril@621
     8
QString quotemeta(const QString &s)
insilmaril@621
     9
{
insilmaril@621
    10
	QString r=s;
insilmaril@621
    11
    QRegExp  rx("&(?!amp;)");
insilmaril@621
    12
    r.replace ( rx,"&amp;");
insilmaril@621
    13
    rx.setPattern( ">");
insilmaril@621
    14
    r.replace ( rx,"&gt;");
insilmaril@621
    15
    rx.setPattern( "<");
insilmaril@621
    16
    r.replace ( rx,"&lt;");
insilmaril@621
    17
    rx.setPattern( "\"");
insilmaril@621
    18
    r.replace ( rx,"&quot;");
insilmaril@621
    19
    return r;
insilmaril@621
    20
}
insilmaril@621
    21
insilmaril@621
    22
insilmaril@621
    23
insilmaril@621
    24
int XMLObj::actindent=0;		// make instance of actindent
insilmaril@621
    25
insilmaril@621
    26
XMLObj::XMLObj()
insilmaril@621
    27
{
insilmaril@621
    28
    indentwidth=4;
insilmaril@621
    29
}
insilmaril@621
    30
insilmaril@791
    31
XMLObj::~XMLObj()
insilmaril@791
    32
{
insilmaril@791
    33
}
insilmaril@791
    34
insilmaril@621
    35
insilmaril@621
    36
// returns <s at />
insilmaril@621
    37
QString XMLObj::singleElement(QString s, QString at)
insilmaril@621
    38
{
insilmaril@621
    39
    return indent() + "<" + s +" " + at +" " + "/>\n";
insilmaril@621
    40
}
insilmaril@621
    41
insilmaril@621
    42
// returns <s>
insilmaril@621
    43
QString XMLObj::beginElement(QString s)
insilmaril@621
    44
{
insilmaril@621
    45
    return indent() + "<" + s + ">\n";
insilmaril@621
    46
}
insilmaril@621
    47
insilmaril@621
    48
// returns <s at>
insilmaril@621
    49
QString XMLObj::beginElement(QString s, QString at)
insilmaril@621
    50
{
insilmaril@621
    51
    return indent() + "<" + s + " " + at + ">\n";
insilmaril@621
    52
}
insilmaril@621
    53
insilmaril@621
    54
// returns </s>
insilmaril@621
    55
QString XMLObj::endElement(QString s)
insilmaril@621
    56
{
insilmaril@621
    57
    return indent() + "</" + s + ">\n";
insilmaril@621
    58
}
insilmaril@621
    59
insilmaril@621
    60
// returns  at="val"
insilmaril@621
    61
QString XMLObj::attribut(QString at, QString val)
insilmaril@621
    62
{
insilmaril@621
    63
    return " " + at + "=\"" + quotemeta (val) + "\""; 
insilmaril@621
    64
}
insilmaril@621
    65
insilmaril@621
    66
// returns <s> val </s>
insilmaril@621
    67
QString XMLObj::valueElement(QString el, QString val)
insilmaril@621
    68
{
insilmaril@621
    69
    return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
insilmaril@621
    70
}
insilmaril@621
    71
insilmaril@621
    72
// returns <s at> val </s>
insilmaril@621
    73
QString XMLObj::valueElement(QString el, QString val, QString at)
insilmaril@621
    74
{
insilmaril@621
    75
    return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
insilmaril@621
    76
}
insilmaril@621
    77
insilmaril@621
    78
void XMLObj::incIndent()
insilmaril@621
    79
{
insilmaril@621
    80
    actindent++;
insilmaril@621
    81
}	
insilmaril@621
    82
insilmaril@621
    83
void XMLObj::decIndent()
insilmaril@621
    84
{
insilmaril@621
    85
    actindent--;
insilmaril@621
    86
    if (actindent<0) actindent=0;
insilmaril@621
    87
}	
insilmaril@621
    88
insilmaril@621
    89
QString XMLObj::indent()
insilmaril@621
    90
{
insilmaril@621
    91
    QString s;
insilmaril@621
    92
    int i;
insilmaril@621
    93
    for (i=0; i<actindent*indentwidth; i++)
insilmaril@621
    94
    {
insilmaril@621
    95
		s= s + " ";
insilmaril@621
    96
    }
insilmaril@621
    97
    return s;
insilmaril@621
    98
}	
insilmaril@621
    99