- Timestamp:
- Feb 6, 2014, 11:15:55 PM (11 years ago)
- Location:
- XmlTools2/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
XmlTools2/trunk/optionsparser.cpp
r940 r942 97 97 98 98 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... 100 100 patchFiles << temp[0].remove('"'); // remove the quotes, they are now not needed 101 101 targetXmlFiles << temp[1].remove('"'); -
XmlTools2/trunk/util.cpp
r923 r942 107 107 } 108 108 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 //} 122 123 123 124 QStringList qStringListFromSpacedString(const QString &mySpacedString){ 124 return Util::substring(mySpacedString," ");125 return mySpacedString.split(" "); 125 126 } 126 127 … … 129 130 QList<int> intList; 130 131 131 stringList = Util::substring(mySpacedString," ");132 stringList = mySpacedString.split(" "); 132 133 133 134 foreach(QString value, stringList){ … … 142 143 QList<double> doubleList; 143 144 144 stringList = Util::substring(mySpacedString," ");145 stringList = mySpacedString.split(" "); 145 146 146 147 foreach(QString value, stringList){ -
XmlTools2/trunk/util.h
r935 r942 6 6 #include <QString> 7 7 #include <QStringList> 8 #include <QRegExp>9 8 #include <iostream> // cout, cin etc. 10 9 … … 25 24 QString fullTrim(QString str); 26 25 QString 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); 28 28 QStringList qStringListFromSpacedString(const QString &mySpacedString); 29 29 QStringList getAllFilesByWildcard(const QString &wildcard); … … 51 51 } 52 52 53 // Needs optimization 53 54 inline QStringList QStringToArgsArray(const QString &args){ 54 55 QStringList result; 55 result=Util::substring(args," ");56 int startIdx=0, endIdx=0; 56 57 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 59 82 } 60 83
Note:
See TracChangeset
for help on using the changeset viewer.