source: XmlTools2/trunk/util.h@ 1002

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

XmlTools
Some more little optimizations and updated readme

File size: 2.9 KB
RevLine 
[906]1#ifndef UTIL_H
2#define UTIL_H
3
4#include <QFile>
5#include <QDir>
6#include <QString>
7#include <QStringList>
[964]8#include <QVector>
[906]9#include <iostream> // cout, cin etc.
10
11namespace GlobalVars{
12extern QString AppName;
[920]13extern QString AppExecutable;
[906]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);
[942]27// Use qstring split
28// QStringList substring(const QString &myString, const QString &separator, Qt::CaseSensitivity cs = Qt::CaseSensitive);
[906]29QStringList qStringListFromSpacedString(const QString &mySpacedString);
30QStringList getAllFilesByWildcard(const QString &wildcard);
31QList<int> qListIntFromSpacedString(const QString &mySpacedString);
32QList<double> qListDoubleFromSpacedString(const QString &mySpacedString);
33int indexOfBackward(const QString &myString, const QString &toSearch, int from = -1);
34bool checkEmptySpaces(QStringList toCheck);
35bool checkIfIntegers(QStringList toCheck);
36bool checkIfDoubles(QStringList toCheck);
37bool isStringInteger(QString myString);
38bool isStringDouble(QString myString);
39bool backupFile(QString file);
40bool copyFile(QString src, QString dest);
41// The commented code bellow is a big mistake because toLatin1() creates a temp object that gets
42// destroyed after the semicolon: https://qt-project.org/forums/viewthread/12885 (Volker answer)
43//// Convert a QString to a c string
44//// Caution don't use as for example: std::cout << toCstr(a) << " " << toCstr(b);
45//// as the result will be always a.
46//inline const char* toCstr(const QString &myString){
[935]47// return myString.toUtf8().constData();
[906]48//}
49// Converts a std::string to QString
50inline QString toQString(std::string myString){
51 return QString::fromStdString(myString);
52}
53
[967]54//TODO Needs optimization
[926]55inline QStringList QStringToArgsArray(const QString &args){
56 QStringList result;
[942]57 int startIdx=0, endIdx=0;
[926]58
[942]59 if(!args.isEmpty()){ // if non empty arguments
60
61 while(endIdx<args.length()){
62
63 startIdx=endIdx;
64
65 if(args.at(startIdx)==' '){ // Ignore spaces until a different char is found
66 endIdx++;
67 continue;
68 }
69 else if(args.at(startIdx)!='"'){ // if first character is different from quote it ends with space
70 endIdx=args.indexOf(' ',startIdx+1);
71 }
72 else{ // If is a quote try to get the all the string until next quote
73 endIdx=args.indexOf('"',startIdx+1);
74 }
75
76 if(endIdx==-1) break;
77
78 endIdx++;
79
80 result << args.mid(startIdx,endIdx-startIdx).replace("\"","").trimmed(); // remove quotes
81 }
82
[926]83 }
84
85 return result;
[906]86}
87
[926]88}
89
[906]90#endif // UTIL_H
Note: See TracBrowser for help on using the repository browser.