[nautilus] Properly strip extensions when placing the duplication string
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Properly strip extensions when placing the duplication string
- Date: Mon, 21 Mar 2011 19:05:55 +0000 (UTC)
commit c250b5702329e71c61f6e7f4e26227925c5b1e90
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Mar 21 15:03:43 2011 -0400
Properly strip extensions when placing the duplication string
We use a similar matching filter to the one we use when renaming. It's
not ideal (mimetypes are hardcoded, and probably some are missing), but
at least we're consistent.
https://bugzilla.gnome.org/show_bug.cgi?id=351290
eel/eel-vfs-extensions.c | 28 +++++++++++++++++------
eel/eel-vfs-extensions.h | 1 +
libnautilus-private/nautilus-file-operations.c | 5 ++-
3 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/eel/eel-vfs-extensions.c b/eel/eel-vfs-extensions.c
index 7a11874..d1b9201 100644
--- a/eel/eel-vfs-extensions.c
+++ b/eel/eel-vfs-extensions.c
@@ -97,15 +97,9 @@ eel_make_valid_utf8 (const char *name)
}
char *
-eel_filename_strip_extension (const char * filename_with_extension)
+eel_filename_get_extension_offset (const char *filename)
{
- char *filename, *end, *end2;
-
- if (filename_with_extension == NULL) {
- return NULL;
- }
-
- filename = g_strdup (filename_with_extension);
+ char *end, *end2;
end = strrchr (filename, '.');
@@ -123,6 +117,24 @@ eel_filename_strip_extension (const char * filename_with_extension)
end = end2;
}
}
+ }
+
+ return end;
+}
+
+char *
+eel_filename_strip_extension (const char * filename_with_extension)
+{
+ char *filename, *end;
+
+ if (filename_with_extension == NULL) {
+ return NULL;
+ }
+
+ filename = g_strdup (filename_with_extension);
+ end = eel_filename_get_extension_offset (filename);
+
+ if (end && end != filename) {
*end = '\0';
}
diff --git a/eel/eel-vfs-extensions.h b/eel/eel-vfs-extensions.h
index 8e10e5c..6338fba 100644
--- a/eel/eel-vfs-extensions.h
+++ b/eel/eel-vfs-extensions.h
@@ -49,6 +49,7 @@ char * eel_filename_strip_extension (const char *
void eel_filename_get_rename_region (const char *filename,
int *start_offset,
int *end_offset);
+char * eel_filename_get_extension_offset (const char *filename);
G_END_DECLS
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index 8b16c0a..7372888 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -540,8 +540,9 @@ parse_previous_duplicate_name (const char *name,
const char *tag;
g_assert (name[0] != '\0');
-
- *suffix = strchr (name + 1, '.');
+
+ *suffix = eel_filename_get_extension_offset (name);
+
if (*suffix == NULL || (*suffix)[1] == '\0') {
/* no suffix */
*suffix = "";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]