xmlobj.cpp
author convert-repo
Fri, 23 Jul 2010 16:43:49 +0000
changeset 849 988f1908a7c4
parent 847 43268373032d
permissions -rw-r--r--
update tags
     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 QString quoteUmlaut(const QString &s)
    23 {
    24 	QString r=s;
    25     QRegExp rx( "ü");
    26     r.replace ( rx,"&uuml;");
    27     rx.setPattern( "Ü");
    28     r.replace ( rx,"&Uuml;");
    29     rx.setPattern( "ö");
    30     r.replace ( rx,"&ouml;");
    31     rx.setPattern( "Ö");
    32     r.replace ( rx,"&Ouml;");
    33     rx.setPattern( "ä");
    34     r.replace ( rx,"&auml;");
    35     rx.setPattern( "Ö");
    36     r.replace ( rx,"&Auml;");
    37     rx.setPattern( "ß");
    38     r.replace ( rx,"&szlig;");
    39     rx.setPattern( "€");
    40     r.replace ( rx,"&euro;");
    41     return r;
    42 }
    43 
    44 
    45 
    46 
    47 int XMLObj::actindent=0;		// make instance of actindent
    48 
    49 XMLObj::XMLObj()
    50 {
    51     indentwidth=4;
    52 }
    53 
    54 XMLObj::~XMLObj()
    55 {
    56 }
    57 
    58 
    59 // returns <s at />
    60 QString XMLObj::singleElement(QString s, QString at)
    61 {
    62     return indent() + "<" + s +" " + at +" " + "/>\n";
    63 }
    64 
    65 // returns <s>
    66 QString XMLObj::beginElement(QString s)
    67 {
    68     return indent() + "<" + s + ">\n";
    69 }
    70 
    71 // returns <s at>
    72 QString XMLObj::beginElement(QString s, QString at)
    73 {
    74     return indent() + "<" + s + " " + at + ">\n";
    75 }
    76 
    77 // returns </s>
    78 QString XMLObj::endElement(QString s)
    79 {
    80     return indent() + "</" + s + ">\n";
    81 }
    82 
    83 // returns  at="val"
    84 QString XMLObj::attribut(QString at, QString val)
    85 {
    86     return " " + at + "=\"" + quotemeta (val) + "\""; 
    87 }
    88 
    89 // returns <s> val </s>
    90 QString XMLObj::valueElement(QString el, QString val)
    91 {
    92     return indent() + "<" + el + ">" + quotemeta(val) + "</" +el + ">\n";
    93 }
    94 
    95 // returns <s at> val </s>
    96 QString XMLObj::valueElement(QString el, QString val, QString at)
    97 {
    98     return indent() + "<" + el + " " + at + ">" + quotemeta(val) + "</" +el + ">\n";
    99 }
   100 
   101 void XMLObj::incIndent()
   102 {
   103     actindent++;
   104 }	
   105 
   106 void XMLObj::decIndent()
   107 {
   108     actindent--;
   109     if (actindent<0) actindent=0;
   110 }	
   111 
   112 QString XMLObj::indent()
   113 {
   114     QString s;
   115     int i;
   116     for (i=0; i<actindent*indentwidth; i++)
   117     {
   118 		s= s + " ";
   119     }
   120     return s;
   121 }	
   122