xmlobj.cpp
author insilmaril
Fri, 13 Nov 2009 08:32:03 +0000
changeset 804 14f2b1b15242
parent 791 f1006de05c54
child 847 43268373032d
permissions -rw-r--r--
Several fixes, see tex/vym.changelog for details
     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 XMLObj::~XMLObj()
    32 {
    33 }
    34 
    35 
    36 // returns <s at />
    37 QString XMLObj::singleElement(QString s, QString at)
    38 {
    39     return indent() + "<" + s +" " + at +" " + "/>\n";
    40 }
    41 
    42 // returns <s>
    43 QString XMLObj::beginElement(QString s)
    44 {
    45     return indent() + "<" + s + ">\n";
    46 }
    47 
    48 // returns <s at>
    49 QString XMLObj::beginElement(QString s, QString at)
    50 {
    51     return indent() + "<" + s + " " + at + ">\n";
    52 }
    53 
    54 // returns </s>
    55 QString XMLObj::endElement(QString s)
    56 {
    57     return indent() + "</" + s + ">\n";
    58 }
    59 
    60 // returns  at="val"
    61 QString XMLObj::attribut(QString at, QString val)
    62 {
    63     return " " + at + "=\"" + quotemeta (val) + "\""; 
    64 }
    65 
    66 // returns <s> val </s>
    67 QString XMLObj::valueElement(QString el, QString val)
    68 {
    69     return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
    70 }
    71 
    72 // returns <s at> val </s>
    73 QString XMLObj::valueElement(QString el, QString val, QString at)
    74 {
    75     return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
    76 }
    77 
    78 void XMLObj::incIndent()
    79 {
    80     actindent++;
    81 }	
    82 
    83 void XMLObj::decIndent()
    84 {
    85     actindent--;
    86     if (actindent<0) actindent=0;
    87 }	
    88 
    89 QString XMLObj::indent()
    90 {
    91     QString s;
    92     int i;
    93     for (i=0; i<actindent*indentwidth; i++)
    94     {
    95 		s= s + " ";
    96     }
    97     return s;
    98 }	
    99