make backslashes escapable

BUG: 199005
FIXED-IN: 4.9
This commit is contained in:
Oswald Buddenhagen 2012-07-01 12:39:41 +02:00
parent 84dc11954c
commit 03e91d5242
3 changed files with 34 additions and 6 deletions

View file

@ -307,12 +307,7 @@ static int directCommand(KCmdLineArgs *args)
}
int ret;
QString text = args->getOption( option );
int pos;
while ((pos = text.indexOf( QLatin1String("\\n") )) >= 0)
{
text.replace(pos, 2, QLatin1String("\n"));
}
QString text = Widgets::parseString(args->getOption(option));
if ( type == KMessageBox::WarningContinueCancel ) {
ret = KMessageBox::messageBox( 0, type, text, title, continueButton,

View file

@ -368,3 +368,35 @@ bool Widgets::calendar( QWidget *parent, const QString &title, const QString &te
return retcode;
}
QString Widgets::parseString(const QString &str)
{
QString ret;
ret.reserve(str.size());
bool escaped = false;
for (int i = 0; i < str.size(); i++) {
QChar c = str.at(i);
if (escaped) {
escaped = false;
if (c == '\\') {
ret += c;
} else if (c == 'n') {
ret += '\n';
} else {
kWarning() << qPrintable(QString::fromLatin1("Unrecognized escape sequence \\%1").arg(c));
ret += '\\';
ret += c;
}
} else {
if (c == '\\') {
escaped = true;
} else {
ret += c;
}
}
}
if (escaped) {
kWarning() << "Unterminated escape sequence";
ret += '\\';
}
return ret;
}

View file

@ -42,6 +42,7 @@ namespace Widgets
void handleXGeometry(QWidget * dlg);
QString parseString(const QString &str);
}
#endif