From: Rogutes <ro...@go...> - 2008-11-27 19:36:14
|
Hello, If my patch seems awkward (I hardly know C and just tried to mimic the surrounding code), then this is a feature request. 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" so Old: title (1999).xxx title (2000).yyy title (1980).zzz would become New: [1999]: title.xxx [2000]: title.yyy [1980]: title.zzz -- Regards, Rogutės |
From: Thomas L. <ta...@gm...> - 2008-11-30 10:44:11
|
2008/11/27 Rogutes <ro...@go...>: > 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. Thanks! -- Dr Thomas Leonard ROX desktop / Zero Install GPG: 9242 9807 C985 3C07 44A6 8B9A AE07 8280 59A5 3CC1 |
From: Rogutes <ro...@go...> - 2008-11-30 15:38:44
|
Thomas Leonard (2008-11-30 10:44): > 2008/11/27 Rogutes <ro...@go...>: > > 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? Thanks, Rogutės |
From: Thomas L. <ta...@gm...> - 2008-11-30 16:18:17
|
2008/11/30 Rogutes <ro...@go...>: > Thomas Leonard (2008-11-30 10:44): >> 2008/11/27 Rogutes <ro...@go...>: >> > 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 |
From: Rogutės <ro...@go...> - 2008-12-05 02:41:22
|
Thomas Leonard (2008-11-30 10:44): > 2008/11/27 Rogutes <ro...@go...>: > > 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. I have attached an updated patch. Looks much better now, thanks for the advice! I haven't added the REG_EXTENDED cflag to regcomp() in this patch, but I agree that it could be the default. -- Rogutės |
From: Thomas L. <ta...@gm...> - 2008-12-05 20:37:30
|
2008/12/5 Rogutės <ro...@go...>: > Thomas Leonard (2008-11-30 10:44): >> 2008/11/27 Rogutes <ro...@go...>: >> > 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" [...] > I have attached an updated patch. Looks much better now, thanks for the > advice! > I haven't added the REG_EXTENDED cflag to regcomp() in this patch, but > I agree that it could be the default. OK - applied! I added the extended flag, and some unit-tests (edit global.h to enable them). I think there was a minor problem with patterns of the form \\\1 This now results in a \ followed by the substitution. Does it look OK? http://repo.or.cz/w/rox-filer.git?a=commitdiff;h=a13d71545be69c651f4cf9a050153fb7094f24d2;hp=f928d8d5ec2102f00bf84e90da552f65c17c5730 Thanks! -- Dr Thomas Leonard ROX desktop / Zero Install GPG: 9242 9807 C985 3C07 44A6 8B9A AE07 8280 59A5 3CC1 |
From: Rogutės <ro...@go...> - 2008-12-05 22:11:46
|
Thomas Leonard (2008-12-05 20:37): > OK - applied! > > I added the extended flag, and some unit-tests (edit global.h to > enable them). I think there was a minor problem with patterns of the > form > > \\\1 I think I did this on purpose, but I am not sure why anymore (it must have been some wry thinking). The way you fixed it looks good and consistent. > This now results in a \ followed by the substitution. Does it look OK? > > http://repo.or.cz/w/rox-filer.git?a=commitdiff;h=a13d71545be69c651f4cf9a050153fb7094f24d2;hp=f928d8d5ec2102f00bf84e90da552f65c17c5730 Yes, the final commit looks fine. Thanks. -- Rogutės |