Re: [patch] support back-references when bulk renaming

"Thomas Leonard" <[email protected]> Sun, 30 Nov 2008 16:18:12 +0000
Newsgroups gmane.comp.desktop.rox.devel
Message-ID <[email protected]>
2008/11/30 Rogutes <[email protected]>:
> Thomas Leonard (2008-11-30 10:44):
>> 2008/11/27 Rogutes <[email protected]>:
>> > Hello,
>> >
>> > I thought it would be nice to have back-references support in the bulk
>> > renaming dialog, so one could, for example, type
>> >
>> > Replace: "\(.*\) (\([0-9]\{4\}\))"
>> > With: "[\2]: \1"
>>
>> > If my patch seems awkward (I hardly know C and just tried to mimic the
>> > surrounding code), then this is a feature request.
>>
>> Looks pretty good (and useful). I think your array may be one element
>> too small (whole pattern plus nine back-refs = 10 offsets).
>>
>> You might find the code would be simpler if you used the g_string_*
>> functions rather than realloc (e.g. g_string_append):
>>
>> http://library.gnome.org/devel/glib/unstable/glib-Strings.html
>>
>> 1. Append everything before the match
>> 2. Append the characters in the with string, expanding references as you go
>> 3. Append everything after the match
>>
>> Do you want to update the patch? If not, I'll try to find some time to
>> do it myself.
>
> Only standard str* functions were used in bulk_rename.c and I thought
> I should do the same (it looks like I should've asked)...
>
> Ok, I will try to update the patch and make the code simpler.
>
> By the way, I find extended regular expressions more comfortable to use
> when replacing with back-references.
> Right now one has to use "\(.*\) (\([0-9]\{4\}\))", but it could be
>                         "(.*) \(([0-9]{4})\)", if REG_EXTENDED cflag
> were set in regcomp(). Would an options for this be acceptable? Perhaps
> by adding a checkbox at the bottom of the dialog?

According to regex(7):

  Regular  expressions  ("RE"s),  as  defined in POSIX.2, come in two
forms: modern REs (roughly those of egrep; POSIX.2 calls these
"extended" REs) and obsolete REs (roughly those of ed(1); POSIX.2
"basic" REs).  Obsolete REs mostly exist for backward compatibility in
some old programs [...]

So, using EXTENDED sounds like the right thing to do in all cases.


-- 
Dr Thomas Leonard		ROX desktop / Zero Install
GPG: 9242 9807 C985 3C07 44A6  8B9A AE07 8280 59A5 3CC1

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/