6 #include <QtCore/QFile>
7 #include <QtCore/QTextStream>
10 bool CSSTemplate::expandToFile(const QString
& outputFilename
, const QMap
<QString
,QString
> &dict
)
12 QFile
inf(m_templateFilename
);
13 if (!inf
.open(QIODevice::ReadOnly
)) return false;
16 QFile
outf(outputFilename
);
17 if (!outf
.open(QIODevice::WriteOnly
)) return false;
18 QTextStream
os(&outf
);
20 doExpand(is
, os
, dict
);
27 QString
CSSTemplate::expandToString(const QMap
<QString
,QString
> &dict
)
29 QFile
inf(m_templateFilename
);
30 if (!inf
.open(QIODevice::ReadOnly
)) return QString();
36 doExpand(is
, os
, dict
);
43 // bool CSSTemplate::expand(const QString &destname, const QMap<QString,QString> &dict)
44 void CSSTemplate::doExpand(QTextStream
&is
, QTextStream
&os
, const QMap
<QString
,QString
> &dict
)
51 int start
= line
.indexOf('$');
54 int end
= line
.indexOf('$', start
+1);
57 QString expr
= line
.mid(start
+1, end
-start
-1);
58 QString res
= dict
[expr
];
60 line
.replace(start
, end
-start
+1, res
);