[SCRIPT] automated removal of RTL_CONSTASCII_USTRINGPARAM for quoted ...

Thomas Arnhold thomas-libo at arnhold.org
Wed Mar 20 06:53:23 PDT 2013


On 20.03.2013 12:09, Stephan Bergmann wrote:
> On 03/19/2013 07:38 PM, Thomas Arnhold wrote:
>> #!/usr/bin/perl
>>
>> # git grep 'RTL_CONSTASCII_USTRINGPARAM' -- '*.[hc]xx' | cut -d':' -f1
>> | sort -u | xargs perl constascii.pl
>>
>> foreach (@ARGV) {
>>     my $file = $_;
>>     my $data = "";
>>     my $fh;
>>
>>     open($fh, "<$file");
>>     while (<$fh>) { $data .= $_; }
>>     close($fh);
>>
>>     # replace OUString(RTL_...)
>>     $data =~
>> s/OUString\s*\(\s*RTL_CONSTASCII_USTRINGPARAM\s*\((\s*"[^")]*?"\s*)\)\s*\)/OUString\($1\)/gms;
>>
>
> BTW, did this work by luck, not causing any damage in cases like
>
>    OUString(RTL_CONSTASCII_USTRINGPARAM("\")"))

More or less, because I found no occurrences of that (the two closing 
brackets after " are limiting it. It would look quite behind \" for two 
closing brackets.

(head at fe8eba5faa59ddf9ee82f3eb009daac72a0ec846)
git grep -w RTL_CONSTASCII_USTRINGPARAM -- '*.[ch]xx' | grep '\\\"\s*)\s*)'
fpicker/source/win32/filepicker/shared.hxx:const ::rtl::OUString 
BACKSLASH(RTL_CONSTASCII_USTRINGPARAM( "\\" ));
fpicker/source/win32/folderpicker/WinFOPImpl.cxx:const OUString 
BACKSLASH(RTL_CONSTASCII_USTRINGPARAM( "\\" ));

But those are safe.

Indeed this regex isn't safe for other conversions of this macro, where 
this case may occur. There [^")\\]*? should be used to omit those.

Thomas


More information about the LibreOffice mailing list