src/types.cpp

changeset 37
c82a86ea87be
parent 36
b8fa9171be6e
child 38
db677d321cf4
equal deleted inserted replaced
36:b8fa9171be6e 37:c82a86ea87be
1 /*
2 * ZCinema: Zandronum demo launcher
3 * Copyright (C) 2013 Santeri Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <QObject>
20 #include <QStringList>
21 #include <QTextStream>
22 #include <assert.h>
23 #include "types.h"
24
25 str doFormat (initlist<StringFormatArg> args) {
26 assert (args.size() >= 1);
27 str text = args.begin()->value();
28
29 for (initlist<StringFormatArg>::iterator it = args.begin() + 1; it != args.end(); ++it)
30 text = text.arg (it->value());
31
32 return text;
33 }
34
35 void doPrint (FILE* fp, initlist<StringFormatArg> args) {
36 fprintf (fp, "%s", doFormat (args).toStdString().c_str());
37 }
38
39 // =============================================================================
40 StringFormatArg::StringFormatArg (const str& v) { m_val = v; }
41 StringFormatArg::StringFormatArg (const char& v) { m_val = v; }
42 StringFormatArg::StringFormatArg (const uchar& v) { m_val = v; }
43 StringFormatArg::StringFormatArg (const QChar& v) { m_val = v; }
44 StringFormatArg::StringFormatArg (const float& v) { m_val = str::number (v); }
45 StringFormatArg::StringFormatArg (const double& v) { m_val = str::number (v); }
46 StringFormatArg::StringFormatArg (const char* v) { m_val = v; }
47 StringFormatArg::StringFormatArg (const void* v) { m_val.sprintf ("%p", v); }

mercurial