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

Legend:
Removed from v.1476  
changed lines
  Added in v.1513

  ViewVC Help
Powered by ViewVC