1
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 ** Contact: Qt Software Information (qt-info@nokia.com)
|
|
5 **
|
|
6 ** This file is part of the tools applications of the Qt Toolkit.
|
|
7 **
|
|
8 ** Commercial Usage
|
|
9 ** Licensees holding valid Qt Commercial licenses may use this file in
|
|
10 ** accordance with the Qt Commercial License Agreement provided with the
|
|
11 ** Software or, alternatively, in accordance with the terms contained in
|
|
12 ** a written agreement between you and Nokia.
|
|
13 **
|
|
14 **
|
|
15 ** GNU General Public License Usage
|
|
16 ** Alternatively, this file may be used under the terms of the GNU
|
|
17 ** General Public License versions 2.0 or 3.0 as published by the Free
|
|
18 ** Software Foundation and appearing in the file LICENSE.GPL included in
|
|
19 ** the packaging of this file. Please review the following information
|
|
20 ** to ensure GNU General Public Licensing requirements will be met:
|
|
21 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
22 ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
|
|
23 ** exception, Nokia gives you certain additional rights. These rights
|
|
24 ** are described in the Nokia Qt GPL Exception version 1.3, included in
|
|
25 ** the file GPL_EXCEPTION.txt in this package.
|
|
26 **
|
|
27 ** Qt for Windows(R) Licensees
|
|
28 ** As a special exception, Nokia, as the sole copyright holder for Qt
|
|
29 ** Designer, grants users of the Qt/Eclipse Integration plug-in the
|
|
30 ** right for the Qt/Eclipse Integration to link to functionality
|
|
31 ** provided by Qt Designer and its related libraries.
|
|
32 **
|
|
33 ** If you are unsure which license is appropriate for your use, please
|
|
34 ** contact the sales department at qt-sales@nokia.com.
|
|
35 **
|
|
36 ****************************************************************************/
|
|
37
|
|
38 #ifndef UTILS_H
|
|
39 #define UTILS_H
|
|
40
|
|
41 #include "ui4.h"
|
|
42 #include <QtCore/QString>
|
|
43 #include <QtCore/QList>
|
|
44 #include <QtCore/QHash>
|
|
45
|
|
46 QT_BEGIN_NAMESPACE
|
|
47
|
|
48 inline bool toBool(const QString &str)
|
|
49 { return str.toLower() == QLatin1String("true"); }
|
|
50
|
|
51 inline QString toString(const DomString *str)
|
|
52 { return str ? str->text() : QString(); }
|
|
53
|
|
54 inline QString fixString(const QString &str, const QString &indent)
|
|
55 {
|
|
56 QString cursegment;
|
|
57 QStringList result;
|
|
58 const QByteArray utf8 = str.toUtf8();
|
|
59 const int utf8Length = utf8.length();
|
|
60
|
|
61 for (int i = 0; i < utf8Length; ++i) {
|
|
62 const uchar cbyte = utf8.at(i);
|
|
63 if (cbyte >= 0x80) {
|
|
64 cursegment += QLatin1Char('\\');
|
|
65 cursegment += QString::number(cbyte, 8);
|
|
66 } else {
|
|
67 switch(cbyte) {
|
|
68 case '\\':
|
|
69 cursegment += QLatin1String("\\\\"); break;
|
|
70 case '\"':
|
|
71 cursegment += QLatin1String("\\\""); break;
|
|
72 case '\r':
|
|
73 break;
|
|
74 case '\n':
|
|
75 cursegment += QLatin1String("\\n\"\n\""); break;
|
|
76 default:
|
|
77 cursegment += QLatin1Char(cbyte);
|
|
78 }
|
|
79 }
|
|
80
|
|
81 if (cursegment.length() > 1024) {
|
|
82 result << cursegment;
|
|
83 cursegment.clear();
|
|
84 }
|
|
85 }
|
|
86
|
|
87 if (!cursegment.isEmpty())
|
|
88 result << cursegment;
|
|
89
|
|
90
|
|
91 QString joinstr = QLatin1String("\"\n");
|
|
92 joinstr += indent;
|
|
93 joinstr += indent;
|
|
94 joinstr += QLatin1Char('"');
|
|
95
|
|
96 QString rc(QLatin1Char('"'));
|
|
97 rc += result.join(joinstr);
|
|
98 rc += QLatin1Char('"');
|
|
99 return rc;
|
|
100 }
|
|
101
|
|
102 inline QHash<QString, DomProperty *> propertyMap(const QList<DomProperty *> &properties)
|
|
103 {
|
|
104 QHash<QString, DomProperty *> map;
|
|
105
|
|
106 for (int i=0; i<properties.size(); ++i) {
|
|
107 DomProperty *p = properties.at(i);
|
|
108 map.insert(p->attributeName(), p);
|
|
109 }
|
|
110
|
|
111 return map;
|
|
112 }
|
|
113
|
|
114 inline QStringList unique(const QStringList &lst)
|
|
115 {
|
|
116 QHash<QString, bool> h;
|
|
117 for (int i=0; i<lst.size(); ++i)
|
|
118 h.insert(lst.at(i), true);
|
|
119 return h.keys();
|
|
120 }
|
|
121
|
|
122 QT_END_NAMESPACE
|
|
123
|
|
124 #endif // UTILS_H
|