static string protectQuotes (const string theText)
{
string aRes (theText);
- for (unsigned int pos = 0; pos < aRes.size(); pos+=2) {
+ unsigned int pos;
+
+ // screen back slash
+ for (pos = 0; pos < aRes.size(); pos++) {
+ pos = aRes.find("\\", pos);
+ if (pos < 0 || pos > aRes.size()) break;
+
+ aRes.insert(pos, "\\");
+ pos++;
+
+ // screen symbol after back slash (except single quote, which will be processed below)
+ if (pos + 1 < aRes.size() && aRes[pos + 1] != '\'') {
+ aRes.insert(pos + 1, "\\");
+ pos++;
+ }
+ }
+
+ // screen single quote
+ for (pos = 0; pos < aRes.size(); pos++) {
pos = aRes.find("'", pos);
if (pos < 0 || pos > aRes.size()) break;
- aRes.replace(pos, 1, "\\\'");
+
+ aRes.insert(pos, "\\");
+ pos++;
}
+
return aRes;
}