Back to index

scribus-ng  1.3.4.dfsg+svn20071115
saxiohelper.cpp
Go to the documentation of this file.
00001 
00002 #include "saxiohelper.h"
00003 #include "saxio.h"
00004 #include "scfonts.h"
00005 #include "fpointarray.h"
00006 
00007 
00008 
00009 
00010 const Xml_string SaxIO::saxxDefaultElem("");
00011 
00012 
00013 
00014 Xml_string mkXMLName(const QString& any)
00015 {
00016        QString result("");
00017        for (unsigned int i=0; i < any.length(); ++i)
00018        {
00019               unsigned int ch = any[i].unicode();
00020               if (ch == ':' || ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')
00021                      || (0xC0 <= ch && ch <= 0xD6) || (0xD8 <= ch && ch <= 0xF6)
00022                      || (0xF8 <= ch && ch <= 0x2FF) || (0x370 <= ch && ch <= 0x37D)
00023                      || (0x37F <= ch && ch <= 0x1FFF) || (0x200C <= ch && ch <= 0x200D)
00024                      || (0x2070 <= ch && ch <= 0x218F) || (0x2C00 <= ch && ch <= 0x2FEF)
00025                      || (0x3001 <= ch && ch <= 0xD7FF) || (0xF900 <= ch && ch <= 0xFDCF)
00026                      || (0xFDF0 <= ch && ch <= 0xFFFD) || ch > 0xFFFF
00027                      || (i > 0 && (ch == '-' || ch == '.' || ('0' <= ch && ch <= '9') || ch == 0xB7
00028                                             || (0x300 <= ch && ch <= 0x36F) || (0x203F <= ch && ch <= 0x2040) )))
00029               {
00030                      result += ch;
00031               }
00032               else
00033               {
00034                      result += '_';
00035                      result += "0123456789ABCDEF"[(ch >> 12) & 15];
00036                      result += "0123456789ABCDEF"[(ch >>  8) & 15];
00037                      result += "0123456789ABCDEF"[(ch >>  4) & 15];
00038                      result += "0123456789ABCDEF"[(ch      ) & 15];
00039               }
00040        }
00041        return result;
00042 }
00043 
00044 /*
00045  NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] 
00046  | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
00047  NameChar        ::=        NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
00048 */
00049 
00050 
00051 // FIXME: this is too Qt dependent
00052 Xml_string toXMLString(unsigned int val)
00053 {
00054        return QString::number(val);
00055 }
00056 
00057 unsigned int parseUInt(const Xml_string& str)
00058 {
00059        return str.toUInt();
00060 }
00061 
00062 Xml_string toXMLString(int val)
00063 {
00064        return QString::number(val);
00065 }
00066 
00067 
00068 int parseInt(const Xml_string& str)
00069 {
00070        return str.toInt();
00071 }
00072 
00073 
00074 Xml_string toXMLString(unsigned long val)
00075 {
00076        return QString::number(val);
00077 }
00078 
00079 unsigned long parseULong(const Xml_string& str)
00080 {
00081        return str.toULong();
00082 }
00083 
00084 Xml_string toXMLString(long val)
00085 {
00086        return QString::number(val);
00087 }
00088 
00089 
00090 long parseLong(const Xml_string& str)
00091 {
00092        return str.toLong();
00093 }
00094 
00095 
00096 Xml_string toXMLString(double val)
00097 {
00098        return QString::number(val);
00099 }
00100 
00101 
00102 double parseDouble(const Xml_string& str)
00103 {
00104        return str.toDouble();
00105 }
00106 
00107 
00108 Xml_string toXMLString(float val)
00109 {
00110        return QString::number(val);
00111 }
00112 
00113 
00114 float parseFloat(const Xml_string& str)
00115 {
00116        return str.toFloat();
00117 }
00118 
00119 
00120 Xml_string toXMLString(bool what)
00121 {
00122        return what? "yes" : "no";
00123 }
00124 
00125 
00126 bool parseBool(const Xml_string& str)
00127 {
00128        return str == "yes";
00129 }
00130 
00131 
00132 Xml_string toXMLString(const Xml_string& val)
00133 {
00134        return val;
00135 }
00136 
00137 
00138 Xml_string toXMLString(const QValueList<double>& doublelist)
00139 {
00140        QString result = "";
00141        QValueList<double>::const_iterator dax;
00142        for (dax = doublelist.begin(); dax != doublelist.end(); ++dax)
00143               result += toXMLString(*dax) + " ";
00144        return result;
00145 }
00146 
00147 
00148 QValueList<double> parseDoubleList(const Xml_string&  str)
00149 {
00150        QStringList strlist = QStringList::split(' ', str);
00151        QValueList<double> result;
00152        for (QStringList::iterator it=strlist.begin(); it != strlist.end(); ++it)
00153               result.append(parseDouble(*it));
00154        return result;
00155 }
00156 
00157 
00158 Xml_string toXMLString(const QValueList<int>& intlist)
00159 {
00160        QString result = "";
00161        QValueList<int>::const_iterator dax;
00162        for (dax = intlist.begin(); dax != intlist.end(); ++dax)
00163               result += toXMLString(*dax) + " ";
00164        return result;
00165 }
00166 
00167 
00168 
00169 QValueList<int> parseIntList(const Xml_string& str)
00170 {
00171        QStringList strlist = QStringList::split(' ', str);
00172        QValueList<int> result;
00173        for (QStringList::iterator it=strlist.begin(); it != strlist.end(); ++it)
00174               result.append(parseInt(*it));
00175        return result;
00176 }
00177 
00178 
00179 QValueStack<int> parseIntStack(const Xml_string& str)
00180 {
00181        QStringList strlist = QStringList::split(' ', str);
00182        QValueStack<int> result;
00183        for (QStringList::iterator it=strlist.begin(); it != strlist.end(); ++it)
00184               result.append(parseInt(*it));
00185        return result;
00186 }
00187 
00188 
00189 Xml_string toXMLString(const QStringList& list)
00190 {
00191        QString result = "";
00192        QStringList::const_iterator dax;
00193        for (dax = list.begin(); dax != list.end(); ++dax)
00194               result += *dax + " ";
00195        return result;
00196 }
00197 
00198 
00199 QStringList parseStringList(const Xml_string&  str)
00200 {
00201        return QStringList::split(' ', str);
00202 }
00203 
00204 
00205 // FIXME: the following should not be in desaxe:
00206 Xml_string toXMLString(const ScFace& val)
00207 {
00208        return val.scName();
00209 }
00210 
00211 
00212 Xml_string toXMLString(const FPointArray& path)
00213 {
00214        return path.svgPath();
00215 }