[gnome-photos] utils: Add photos_utils_filename_strip_extension
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] utils: Add photos_utils_filename_strip_extension
- Date: Fri, 27 Apr 2012 23:21:30 +0000 (UTC)
commit 6d80d4b995235d0481b72b438af19f70804d8a4c
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Apr 28 01:16:05 2012 +0200
utils: Add photos_utils_filename_strip_extension
src/photos-utils.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/photos-utils.h | 2 ++
2 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 54a09e0..9711e52 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -21,6 +21,10 @@
#include "config.h"
+#include <string.h>
+
+#include <glib.h>
+
#include "photos-utils.h"
@@ -30,3 +34,49 @@ photos_utils_alpha_gtk_widget (GtkWidget *widget)
GdkRGBA color = {0.0, 0.0, 0.0, 0.0};
gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &color);
}
+
+
+static gchar *
+photos_utils_filename_get_extension_offset (const gchar *filename)
+{
+ gchar *end;
+ gchar *end2;
+
+ end = strrchr (filename, '.');
+
+ if (end != NULL && end != filename)
+ {
+ if (g_strcmp0 (end, ".gz") == 0
+ || g_strcmp0 (end, ".bz2") == 0
+ || g_strcmp0 (end, ".sit") == 0
+ || g_strcmp0 (end, ".Z") == 0)
+ {
+ end2 = end - 1;
+ while (end2 > filename && *end2 != '.')
+ end2--;
+ if (end2 != filename)
+ end = end2;
+ }
+ }
+
+ return end;
+}
+
+
+gchar *
+photos_utils_filename_strip_extension (const gchar *filename_with_extension)
+{
+ gchar *end;
+ gchar *filename;
+
+ if (filename_with_extension == NULL)
+ return NULL;
+
+ filename = g_strdup (filename_with_extension);
+ end = photos_utils_filename_get_extension_offset (filename);
+
+ if (end != NULL && end != filename)
+ *end = '\0';
+
+ return filename;
+}
diff --git a/src/photos-utils.h b/src/photos-utils.h
index a15e885..41840e9 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -27,6 +27,8 @@ G_BEGIN_DECLS
void photos_utils_alpha_gtk_widget (GtkWidget *widget);
+gchar *photos_utils_filename_strip_extension (const gchar *filename_with_extension);
+
G_END_DECLS
#endif /* PHOTOS_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]