src/types.cpp

Tue, 16 Jul 2013 23:53:31 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Jul 2013 23:53:31 +0300
changeset 0
bb264814dd81
child 1
c9b22c06307c
permissions
-rw-r--r--

Initial commit

0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 #include <QObject>
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 #include <QStringList>
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 #include <QTextStream>
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 #include <assert.h>
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 #include "types.h"
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 str doFormat( std::vector<StringFormatArg> args ) {
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 assert( args.size() >= 1 );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 str text = args[0].value();
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 for( uchar i = 1; i < args.size(); ++i )
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 text = text.arg( args[i].value() );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 return text;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 void doPrint( initlist<StringFormatArg> args ) {
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 printf( "%s", doFormat( args ).toStdString().c_str() );
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 // =============================================================================
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 StringFormatArg::StringFormatArg( const str& v ) { m_val = v; }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 StringFormatArg::StringFormatArg( const char& v ) { m_val = v; }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 StringFormatArg::StringFormatArg( const uchar& v ) { m_val = v; }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 StringFormatArg::StringFormatArg( const qchar& v ) { m_val = v; }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 StringFormatArg::StringFormatArg( const float& v ) { m_val = str::number( v ); }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 StringFormatArg::StringFormatArg( const double& v ) { m_val = str::number( v ); }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 StringFormatArg::StringFormatArg( const char* v ) { m_val = v; }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 StringFormatArg::StringFormatArg( const void* v ) { m_val.sprintf( "%p", v ); }

mercurial