[Konversation-devel] [Bug 218332] New: No way to output '%1' in autoreplace
Nicolás Alvarez
nicolas.alvarez at gmail.com
Fri Dec 11 22:49:12 CET 2009
https://bugs.kde.org/show_bug.cgi?id=218332
Summary: No way to output '%1' in autoreplace
Product: konversation
Version: Git
Platform: Compiled Sources
OS/Version: Linux
Status: UNCONFIRMED
Severity: normal
Priority: NOR
Component: general
AssignedTo: konversation-devel at kde.org
ReportedBy: nicolas.alvarez at gmail.com
In a regex autoreplace, it's impossible to output a literal percent sign
followed by a number. If I have a regex "foo-(\S*)" and replacement "bar%23%1",
"foo-x" will output "bar3x", because the %2 is interpreted as a capturing
subpattern, even though the regex only has one subpattern.
The current code is:
// replace %0 - %9 in regex groups
for (int capture=0;capture<captures.count();capture++)
{
replacement.replace(QString("%%1").arg(capture),captures[capture]);
}
replacement.remove(QRegExp("%[0-9]"));
Removing the last line would allow the previous example to work. However, it
still doesn't solve the problem if I *do* have a second subpattern (or if I
want to output %1). What we really need is a way to escape the percent sign.
Instead of using replace(), I propose looping over the characters in the
string. Pseudocode:
foreach (char in string) {
if (char == %) {
look at the following character;
if (char == %) output += '%'; //this lets you escape a % by doubling it
if (char is digit) output += capture[digit];
else output += '%' + char;
} else {
output += char;
}
}
I may implement this myself later.
--
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the Konversation-devel
mailing list