--
Regards,
Gehad Elrobey

>From 7fe2e050df5170a88ada31ec6b876ee1cd0b3640 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Tue, 1 Apr 2014 00:50:58 +0200
Subject: [PATCH] Fixing dive notes escape characters in worldmap exporter

Replacing the newlines in the string with <br> and changing the single
quote to its HTML number.

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
---
 worldmap-save.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/worldmap-save.c b/worldmap-save.c
index f9a4bf3..375b8e0 100644
--- a/worldmap-save.c
+++ b/worldmap-save.c
@@ -27,10 +27,47 @@ void put_HTML_temp(struct membuffer *b,struct dive *dive)
 	put_temperature(b, dive->watertemp, "<p>Water Temp: ", " C\\'</p>");
 }
 
+char* replace_char(char * str,char* replace_by , char replace)
+{
+	/*
+		this fumction can't replace a character with a substring
+		where the substring contains the character, infinte loop.
+	*/
+
+	char* result = malloc(( strlen(str) + 1 ) * sizeof(char) );
+	strcpy(result,str);
+	char* ptr = strchr(result,replace);
+	while (ptr) {
+		result = realloc(result ,( strlen(replace_by) + strlen(result) ) * sizeof(char));
+		if (!result) {
+			printf("Error");
+			return 0;
+		}
+		ptr = strchr(result,replace);/* search for char after realloc*/
+		char* temp = malloc( (strlen(replace_by) + strlen(result) ) * sizeof(char));
+		*ptr='\0';
+		strcpy(temp,result);
+		strcat(temp,replace_by);
+		strcat(temp,ptr+1);
+		strcpy(result,temp);
+		free(temp);
+		ptr = strchr(result,replace);
+	}
+    return result;
+}
+
+char* quote(char * string)
+{
+	char* new_line_removed = replace_char(string,"<br>",'\n');
+	char* single_quotes_removed = replace_char(new_line_removed,"&#39;",'\'');
+	free(new_line_removed);
+	return single_quotes_removed;
+}
+
 void put_HTML_notes(struct membuffer *b,struct dive *dive)
 {
 	if (dive->notes) {
-		put_format(b,"<p>Notes : %s </p>",dive->notes);
+		put_format(b,"<p>Notes : %s </p>",quote(dive->notes));
 	}
 }
 
-- 
1.8.3.2

_______________________________________________
subsurface mailing list
subsurface@hohndel.org
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to