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