/[svn]/qsampler/trunk/src/qsamplerUtilities.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerUtilities.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1498 by senoner, Sun Nov 11 23:07:06 2007 UTC revision 1499 by capela, Tue Nov 20 16:48:04 2007 UTC
# Line 24  Line 24 
24    
25  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
26    
27  #include <stdio.h>  #include <QRegExp>
28  #include <qregexp.h>  
29    
30  using namespace QSampler;  using namespace QSampler;
31    
# Line 84  QString lscpEscapePath ( const QString& Line 84  QString lscpEscapePath ( const QString&
84      // TODO: missing code for other systems like Windows      // TODO: missing code for other systems like Windows
85      {      {
86          QRegExp regexp("%[0-9a-fA-F][0-9a-fA-F]");          QRegExp regexp("%[0-9a-fA-F][0-9a-fA-F]");
87          for (int i = path.find(regexp); i >= 0; i = path.find(regexp, i + 4))          for (int i = path.indexOf(regexp); i >= 0; i = path.indexOf(regexp, i + 4))
88              path.replace(i, 1, "\\x");              path.replace(i, 1, "\\x");
89      }      }
90      // replace POSIX path escape sequence (%%) by its raw character      // replace POSIX path escape sequence (%%) by its raw character
91      for (int i = path.find("%%"); i >= 0; i = path.find("%%", ++i))      for (int i = path.indexOf("%%"); i >= 0; i = path.indexOf("%%", ++i))
92          path.remove(i, 1);          path.remove(i, 1);
93    
94      // replace all non-basic characters by LSCP escape sequences      // replace all non-basic characters by LSCP escape sequences
# Line 97  QString lscpEscapePath ( const QString& Line 97  QString lscpEscapePath ( const QString&
97          QRegExp regexp(QRegExp::escape("\\x") + "[0-9a-fA-F][0-9a-fA-F]");          QRegExp regexp(QRegExp::escape("\\x") + "[0-9a-fA-F][0-9a-fA-F]");
98          for (int i = 0; i < int(path.length()); i++) {          for (int i = 0; i < int(path.length()); i++) {
99              // first skip all previously added LSCP escape sequences              // first skip all previously added LSCP escape sequences
100              if (path.find(regexp, i) == i) {              if (path.indexOf(regexp, i) == i) {
101                  i += 3;                  i += 3;
102                  continue;                  continue;
103              }              }
104              // now match all non-alphanumerics              // now match all non-alphanumerics
105              // (we could exclude much more characters here, but that way              // (we could exclude much more characters here, but that way
106              // we're sure it just works^TM)              // we're sure it just works^TM)
107              const char c = path.at(i).latin1();              const char c = path.at(i).toLatin1();
108              if (              if (
109                  !(c >= '0' && c <= '9') &&                  !(c >= '0' && c <= '9') &&
110                  !(c >= 'a' && c <= 'z') &&                  !(c >= 'a' && c <= 'z') &&
# Line 132  QString lscpEscapedPathToPosix(QString p Line 132  QString lscpEscapedPathToPosix(QString p
132      if (!_remoteSupportsEscapeSequences()) return path;      if (!_remoteSupportsEscapeSequences()) return path;
133    
134      // first escape all percent ('%') characters for POSIX      // first escape all percent ('%') characters for POSIX
135      for (int i = path.find('%'); i >= 0; i = path.find('%', i+2))      for (int i = path.indexOf('%'); i >= 0; i = path.indexOf('%', i+2))
136          path.replace(i, 1, "%%");          path.replace(i, 1, "%%");
137    
138      // resolve LSCP hex escape sequences (\xHH)      // resolve LSCP hex escape sequences (\xHH)
139      QRegExp regexp(QRegExp::escape("\\x") + "[0-9a-fA-F][0-9a-fA-F]");      QRegExp regexp(QRegExp::escape("\\x") + "[0-9a-fA-F][0-9a-fA-F]");
140      for (int i = path.find(regexp); i >= 0; i = path.find(regexp, i + 4)) {      for (int i = path.indexOf(regexp); i >= 0; i = path.indexOf(regexp, i + 4)) {
141          const QString sHex = path.mid(i+2, 2).lower();          const QString sHex = path.mid(i+2, 2).toLower();
142          // the slash has to be escaped for POSIX as well          // the slash has to be escaped for POSIX as well
143          if (sHex == "2f") {          if (sHex == "2f") {
144              path.replace(i, 4, "%2f");              path.replace(i, 4, "%2f");
145              continue;              continue;
146          }          }
147          // all other characters we simply decode          // all other characters we simply decode
148          char cAscii = _hexsToNumber(sHex.at(1).latin1(), sHex.at(0).latin1());          char cAscii = _hexsToNumber(sHex.at(1).toLatin1(), sHex.at(0).toLatin1());
149          path.replace(i, 4, cAscii);          path.replace(i, 4, cAscii);
150      }      }
151    
# Line 159  QString lscpEscapedTextToRaw(QString txt Line 159  QString lscpEscapedTextToRaw(QString txt
159    
160      // resolve LSCP hex escape sequences (\xHH)      // resolve LSCP hex escape sequences (\xHH)
161      QRegExp regexp(QRegExp::escape("\\x") + "[0-9a-fA-F][0-9a-fA-F]");      QRegExp regexp(QRegExp::escape("\\x") + "[0-9a-fA-F][0-9a-fA-F]");
162      for (int i = txt.find(regexp); i >= 0; i = txt.find(regexp, i + 4)) {      for (int i = txt.indexOf(regexp); i >= 0; i = txt.indexOf(regexp, i + 4)) {
163          const QString sHex = txt.mid(i+2, 2).lower();          const QString sHex = txt.mid(i+2, 2).toLower();
164          // decode into raw ASCII character          // decode into raw ASCII character
165          char cAscii = _hexsToNumber(sHex.at(1).latin1(), sHex.at(0).latin1());          char cAscii = _hexsToNumber(sHex.at(1).toLatin1(), sHex.at(0).toLatin1());
166          txt.replace(i, 4, cAscii);          txt.replace(i, 4, cAscii);
167      }      }
168    

Legend:
Removed from v.1498  
changed lines
  Added in v.1499

  ViewVC Help
Powered by ViewVC