[gthumb] Fixed comment synchronization when a \r is in the text
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] Fixed comment synchronization when a \r is in the text
- Date: Sun, 11 Sep 2011 14:32:14 +0000 (UTC)
commit acdab93368177b9ebe50c22a6c7e75671cf7a038
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Sep 11 14:42:35 2011 +0200
Fixed comment synchronization when a \r is in the text
GMarkupParser converts \r into \n, for this reason the saved comment and
the embedded comment must be compared with a function that treats \r
characters as they were equal to \n.
extensions/comments/main.c | 8 ++++----
gthumb/dom.c | 34 ++++++++++++++++++++++++++++++++++
gthumb/dom.h | 5 +++++
3 files changed, 43 insertions(+), 4 deletions(-)
---
diff --git a/extensions/comments/main.c b/extensions/comments/main.c
index 7a7fb83..7b6771e 100644
--- a/extensions/comments/main.c
+++ b/extensions/comments/main.c
@@ -124,7 +124,7 @@ comments__read_metadata_ready_cb (GthFileData *file_data,
metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::description");
if (metadata != NULL) {
text = g_file_info_get_attribute_string (file_data->info, "comment::note");
- if (g_strcmp0 (gth_metadata_get_formatted (metadata), text) != 0) {
+ if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
gth_comment_set_note (comment, gth_metadata_get_formatted (metadata));
write_comment = TRUE;
}
@@ -133,7 +133,7 @@ comments__read_metadata_ready_cb (GthFileData *file_data,
metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::title");
if (metadata != NULL) {
text = g_file_info_get_attribute_string (file_data->info, "comment::caption");
- if (g_strcmp0 (gth_metadata_get_formatted (metadata), text) != 0) {
+ if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
gth_comment_set_caption (comment, gth_metadata_get_formatted (metadata));
write_comment = TRUE;
}
@@ -142,7 +142,7 @@ comments__read_metadata_ready_cb (GthFileData *file_data,
metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::location");
if (metadata != NULL) {
text = g_file_info_get_attribute_string (file_data->info, "comment::place");
- if (g_strcmp0 (gth_metadata_get_formatted (metadata), text) != 0) {
+ if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
gth_comment_set_place (comment, gth_metadata_get_formatted (metadata));
write_comment = TRUE;
}
@@ -153,7 +153,7 @@ comments__read_metadata_ready_cb (GthFileData *file_data,
text = gth_metadata_get_raw (metadata);
metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "comment::time");
if (metadata != NULL) {
- if (g_strcmp0 (gth_metadata_get_raw (metadata), text) != 0) {
+ if (! dom_str_equal (gth_metadata_get_raw (metadata), text)) {
gth_comment_set_time_from_exif_format (comment, gth_metadata_get_raw (metadata));
write_comment = TRUE;
}
diff --git a/gthumb/dom.c b/gthumb/dom.c
index 0a317a1..e460715 100644
--- a/gthumb/dom.c
+++ b/gthumb/dom.c
@@ -791,3 +791,37 @@ dom_domizable_get_type (void)
}
return dom_domizable_type_id;
}
+
+
+/* -- Utilities -- */
+
+/* GMarkupParser converts \r into \n, this function compares two strings
+ * treating \r characters as they were equal to \n */
+gboolean
+dom_str_equal (const char *a,
+ const char *b)
+{
+ const char *ai, *bi;
+
+ if ((a == NULL) && (b == NULL))
+ return TRUE;
+
+ if ((a == NULL) || (b == NULL))
+ return FALSE;
+
+ ai = a;
+ bi = b;
+ while ((*ai != '\0') && (*bi != '\0')) {
+ if (*ai != *bi) {
+ if (! (((*ai == '\r') && (*bi == '\n'))
+ || ((*ai == '\n') && (*bi == '\r'))))
+ {
+ return FALSE;
+ }
+ }
+ ai++;
+ bi++;
+ }
+
+ return *ai == *bi;
+}
diff --git a/gthumb/dom.h b/gthumb/dom.h
index 7294660..20fa4d2 100644
--- a/gthumb/dom.h
+++ b/gthumb/dom.h
@@ -185,6 +185,11 @@ DomElement * dom_domizable_create_element (DomDomizable *self,
void dom_domizable_load_from_element (DomDomizable *self,
DomElement *e);
+/* Utilities */
+
+gboolean dom_str_equal (const char *a,
+ const char *b);
+
G_END_DECLS
#endif /* DOM_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]