2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007, 2008 Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
153 |
return path; |
return path; |
154 |
} |
} |
155 |
|
|
156 |
|
// converts the given text as expected by LSCP 1.2 |
157 |
|
// (that is by encoding special characters with LSCP escape sequences) |
158 |
|
QString lscpEscapeText(const QString& txt) { |
159 |
|
if (!_remoteSupportsEscapeSequences()) return txt; |
160 |
|
|
161 |
|
QString text(txt); |
162 |
|
|
163 |
|
// replace all non-basic characters by LSCP escape sequences |
164 |
|
for (int i = 0; i < int(text.length()); ++i) { |
165 |
|
// match all non-alphanumerics |
166 |
|
// (we could exclude much more characters here, but that way |
167 |
|
// we're sure it just works^TM) |
168 |
|
const char c = text.at(i).toLatin1(); |
169 |
|
if ( |
170 |
|
!(c >= '0' && c <= '9') && |
171 |
|
!(c >= 'a' && c <= 'z') && |
172 |
|
!(c >= 'A' && c <= 'Z') |
173 |
|
) { |
174 |
|
// convert the non-basic character into a LSCP escape sequence |
175 |
|
char buf[5]; |
176 |
|
::snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c)); |
177 |
|
text.replace(i, 1, buf); |
178 |
|
i += 3; |
179 |
|
} |
180 |
|
} |
181 |
|
|
182 |
|
return text; |
183 |
|
} |
184 |
|
|
185 |
// converts a text returned by a LSCP command and may contain escape |
// converts a text returned by a LSCP command and may contain escape |
186 |
// sequences) into raw text, that is with all escape sequences decoded |
// sequences) into raw text, that is with all escape sequences decoded |
187 |
QString lscpEscapedTextToRaw(QString txt) { |
QString lscpEscapedTextToRaw(QString txt) { |