source: XmlTools2/trunk/util.h@ 935

Last change on this file since 935 was 935, checked in by s10k, 11 years ago

XmlTools
Oni's Mac folder use a special character (U+0192), because of this I had to change all encoding transformations to UTF8

File size: 2.2 KB
Line 
1#ifndef UTIL_H
2#define UTIL_H
3
4#include <QFile>
5#include <QDir>
6#include <QString>
7#include <QStringList>
8#include <QRegExp>
9#include <iostream> // cout, cin etc.
10
11namespace GlobalVars{
12extern QString AppName;
13extern QString AppExecutable;
14extern QString AppVersion;
15}
16
17/**
18 Utilities functions (global)
19 **/
20namespace Util{
21QString normalizePath(QString path);
22QString cutName(QString path);
23QString insertQuotes(QString path);
24QString normalizeAndQuote(QString path);
25QString fullTrim(QString str);
26QString normalizeDecimalSeparator(QString value);
27QStringList substring(const QString &myString, const QString &separator, Qt::CaseSensitivity cs = Qt::CaseSensitive);
28QStringList qStringListFromSpacedString(const QString &mySpacedString);
29QStringList getAllFilesByWildcard(const QString &wildcard);
30QList<int> qListIntFromSpacedString(const QString &mySpacedString);
31QList<double> qListDoubleFromSpacedString(const QString &mySpacedString);
32int indexOfBackward(const QString &myString, const QString &toSearch, int from = -1);
33bool checkEmptySpaces(QStringList toCheck);
34bool checkIfIntegers(QStringList toCheck);
35bool checkIfDoubles(QStringList toCheck);
36bool isStringInteger(QString myString);
37bool isStringDouble(QString myString);
38bool backupFile(QString file);
39bool copyFile(QString src, QString dest);
40// The commented code bellow is a big mistake because toLatin1() creates a temp object that gets
41// destroyed after the semicolon: https://qt-project.org/forums/viewthread/12885 (Volker answer)
42//// Convert a QString to a c string
43//// Caution don't use as for example: std::cout << toCstr(a) << " " << toCstr(b);
44//// as the result will be always a.
45//inline const char* toCstr(const QString &myString){
46// return myString.toUtf8().constData();
47//}
48// Converts a std::string to QString
49inline QString toQString(std::string myString){
50 return QString::fromStdString(myString);
51}
52
53inline QStringList QStringToArgsArray(const QString &args){
54 QStringList result;
55 result=Util::substring(args," ");
56
57 for(int i=0; i<result.size(); i++){
58 result[i].remove('"'); // remove quotes, they are not necessary as we had already splited the spaces
59 }
60
61 return result;
62}
63
64}
65
66#endif // UTIL_H
Note: See TracBrowser for help on using the repository browser.