This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: help with pretty printing
- From: <Paul_Koning at Dell dot com>
- To: <joachim dot protze at tu-dresden dot de>
- Cc: <graham dot labdon at avalonsciences dot com>, <gdb at sourceware dot org>
- Date: Thu, 7 Jun 2012 18:26:55 +0000
- Subject: Re: help with pretty printing
- References: <33943560.post@talk.nabble.com> <4FD05B70.7040008@tu-dresden.de>
On Jun 7, 2012, at 3:42 AM, Joachim Protze wrote:
> On 01.06.2012 11:07, somersetgraham wrote:
>> def build_dictionary ():
>> pretty_printers_dict[re.compile ('^QFile$')] = lambda
>> val:QFilePrinter(val)
>> pretty_printers_dict[re.compile ('^QFile *$')] = lambda
>> val:QFilePrinter(val)
> you may try something like the following to match both cases:
>
> pretty_printers_dict[re.compile('^QFile ( \*)?$')] = lambda
> val:QFilePrinter(val)
>
>
> The asterisk is a special character in regular expressions and has to be escaped to match an asterisk. Your regexp matches QFile with any count of spaces as postfix.
>
> - Joachim
Yes, but since you're dealing with a regular (not raw) string here, the \ needs to be doubled, otherwise it is treated as a string character escape instead of a backslash character inside the string. So one of these will match space followed by asterisk:
pretty_printers_dict[re.compile('^QFile ( \\*)?$')] = lambda val:QFilePrinter(val)
pretty_printers_dict[re.compile(r'^QFile ( \*)?$')] = lambda val:QFilePrinter(val)