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 |
|
|
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 |
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') && |
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 |
|
|
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 |
|
|