rewrite of the filename_add_extension() in src/dialogs/export.cpp
Hello there,
I have made a rewrite of the filename_add_extension() in src/dialogs/export.cpp based on the FIXME comment there. I have test script and the patch attached.
Thanks, Muthu
Sorry, I had some comments there. A cleaner patch here.
Index: export.cpp =================================================================== --- export.cpp (revision 13698) +++ export.cpp (working copy) @@ -1125,29 +1125,23 @@ return; } // end of sp_export_export_clicked()
- -// FIXME: Some lib function should be available to do this ... static gchar * filename_add_extension (const gchar *filename, const gchar *extension) { - gchar *dot; - - dot = strrchr (filename, '.'); - if ( !dot ) - return g_strconcat (filename, ".", extension, NULL); - { - if (dot[1] == '\0') - return g_strconcat (filename, extension, NULL); - else - { - if (g_strncasecmp (dot + 1, extension,-1) == 0) - return g_strdup (filename); - else - { - return g_strconcat (filename, ".", extension, NULL); - } - } - } + gchar *dotextension=NULL; + gchar *retval=NULL; + + dotextension=g_strdup_printf(".%s",extension); + + if(g_str_has_suffix(filename,dotextension)) { + retval=g_strdup(filename); + } else if(g_str_has_suffix(filename,".")) { + retval=g_strconcat(filename,extension,NULL); + } else { + retval=g_strconcat(filename,dotextension,NULL); + } + g_free(dotextension); + return retval; }
/// Called when Browse button is clicked
On Fri, 2007-01-12 at 15:13 +0530, Muthiah Annamalai wrote:
Hello there,
I have made a rewrite of the filename_add_extension() in src/dialogs/export.cpp based on the FIXME comment there. I have test script and the patch attached.
Thanks, Muthu
Muthiah Annamalai wrote:
I have made a rewrite of the filename_add_extension() in src/dialogs/export.cpp based on the FIXME comment there. I have test script and the patch attached.
Thank you for your patch to try to find a solution for the fixme. I think it is very praiseworthy to solve fixme's! (note that this fixme is very very young, I wrote the function and the fixme comment a week ago!!)
I'll look into this later today. But let me say that I meant the fixme comment different from how I think you interpreted it. I meant to say that there has to be a library function already present that ensures that the filename ends with a certain extension. The real fix for my fixme comment would be to find that function and replace calls to filename_add_extension() with calls to the lib-function.
Regards, Johan
participants (2)
-
unknown@example.com
-
Muthiah Annamalai