Changeset 942


Ignore:
Timestamp:
Feb 6, 2014, 11:15:55 PM (11 years ago)
Author:
s10k
Message:

XmlTools

Location:
XmlTools2/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • XmlTools2/trunk/optionsparser.cpp

    r940 r942  
    9797
    9898                if(line.startsWith('"')){ // Only read when starting with quotes
    99                     temp=Util::substring(line," \""); // We need to use more than space, because if paths contains spaces...
     99                    temp=line.split(" \""); // We need to use more than space, because if paths contains spaces...
    100100                    patchFiles << temp[0].remove('"'); // remove the quotes, they are now not needed
    101101                    targetXmlFiles << temp[1].remove('"');
  • XmlTools2/trunk/util.cpp

    r923 r942  
    107107}
    108108
    109 QStringList substring(const QString &myString,const QString &separator, Qt::CaseSensitivity cs){
    110     QStringList result = QStringList();
    111     int currIdx=0, nextIdx=0;
    112 
    113     while(true){
    114         nextIdx=myString.indexOf(separator,currIdx,cs);
    115         result << myString.mid(currIdx,nextIdx-currIdx);
    116         if(nextIdx==-1) break;
    117         currIdx=nextIdx+1;
    118     }
    119 
    120     return result;
    121 }
     109// Use qstring split
     110//QStringList substring(const QString &myString,const QString &separator, Qt::CaseSensitivity cs){
     111//    QStringList result = QStringList();
     112//    int currIdx=0, nextIdx=0;
     113
     114//    while(true){
     115//        nextIdx=myString.indexOf(separator,currIdx,cs);
     116//        result << myString.mid(currIdx,nextIdx-currIdx);
     117//        if(nextIdx==-1) break;
     118//        currIdx=nextIdx+1;
     119//    }
     120
     121//    return result;
     122//}
    122123
    123124QStringList qStringListFromSpacedString(const QString &mySpacedString){
    124     return Util::substring(mySpacedString," ");
     125    return mySpacedString.split(" ");
    125126}
    126127
     
    129130    QList<int> intList;
    130131
    131     stringList = Util::substring(mySpacedString," ");
     132    stringList = mySpacedString.split(" ");
    132133
    133134    foreach(QString value, stringList){
     
    142143    QList<double> doubleList;
    143144
    144     stringList = Util::substring(mySpacedString," ");
     145    stringList = mySpacedString.split(" ");
    145146
    146147    foreach(QString value, stringList){
  • XmlTools2/trunk/util.h

    r935 r942  
    66#include <QString>
    77#include <QStringList>
    8 #include <QRegExp>
    98#include <iostream> // cout, cin etc.
    109
     
    2524QString fullTrim(QString str);
    2625QString normalizeDecimalSeparator(QString value);
    27 QStringList substring(const QString &myString, const QString &separator, Qt::CaseSensitivity cs = Qt::CaseSensitive);
     26// Use qstring split
     27// QStringList substring(const QString &myString, const QString &separator, Qt::CaseSensitivity cs = Qt::CaseSensitive);
    2828QStringList qStringListFromSpacedString(const QString &mySpacedString);
    2929QStringList getAllFilesByWildcard(const QString &wildcard);
     
    5151}
    5252
     53// Needs optimization
    5354inline QStringList QStringToArgsArray(const QString &args){
    5455    QStringList result;
    55     result=Util::substring(args," ");
     56    int startIdx=0, endIdx=0;
    5657
    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
     58    if(!args.isEmpty()){ // if non empty arguments
     59
     60        while(endIdx<args.length()){
     61
     62            startIdx=endIdx;
     63
     64            if(args.at(startIdx)==' '){ // Ignore spaces until a different char is found
     65                endIdx++;
     66                continue;
     67            }
     68            else if(args.at(startIdx)!='"'){ // if first character is different from quote it ends with space
     69                endIdx=args.indexOf(' ',startIdx+1);
     70            }
     71            else{ // If is a quote try to get the all the string until next quote
     72                endIdx=args.indexOf('"',startIdx+1);
     73            }
     74
     75            if(endIdx==-1) break;
     76
     77            endIdx++;
     78
     79            result << args.mid(startIdx,endIdx-startIdx).replace("\"","").trimmed(); // remove quotes
     80        }
     81
    5982    }
    6083
Note: See TracChangeset for help on using the changeset viewer.