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