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