From 7df68b2c7da61c00327e54db57e38fcf60e9db2c Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Thu, 10 Aug 2000 18:45:44 +0000 Subject: If converting both spaces and newlines, then convert tabs too. The joys of * e-html-utils.c (e_text_to_html): If converting both spaces and newlines, then convert tabs too. The joys of pseudo-
.

svn path=/trunk/; revision=4695
---
 e-util/e-html-utils.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

(limited to 'e-util/e-html-utils.c')

diff --git a/e-util/e-html-utils.c b/e-util/e-html-utils.c
index 62eb4c5d53..7ff97371eb 100644
--- a/e-util/e-html-utils.c
+++ b/e-util/e-html-utils.c
@@ -113,6 +113,9 @@ url_extract (const unsigned char **text, gboolean check)
  *     which probably means you don't want to use this flag on
  *     pieces of data that aren't delimited by at least line breaks.
  *
+ *     If E_TEXT_TO_HTML_CONVERT_NL and E_TEXT_TO_HTML_CONVERT_SPACES
+ *     are both defined, then TABs will also be converted to spaces.
+ *
  *   - E_TEXT_TO_HTML_CONVERT_URLS: wrap   around
  *     strings that look like URLs.
  **/
@@ -122,7 +125,7 @@ e_text_to_html (const char *input, unsigned int flags)
 	const unsigned char *cur = input, *end;
 	char *buffer = NULL;
 	char *out = NULL;
-	int buffer_size = 0;
+	int buffer_size = 0, col;
 
 	/* Allocate a translation buffer.  */
 	buffer_size = strlen (input) * 2 + 5;
@@ -132,6 +135,7 @@ e_text_to_html (const char *input, unsigned int flags)
 	if (flags & E_TEXT_TO_HTML_PRE)
 		out += sprintf (out, "
\n");
 
+	col = 0;
 	while (*cur) {
 		if (isalpha (*cur) && (flags & E_TEXT_TO_HTML_CONVERT_URLS)) {
 			char *tmpurl = NULL, *refurl = NULL, *dispurl = NULL;
@@ -162,6 +166,7 @@ e_text_to_html (const char *input, unsigned int flags)
 				out += sprintf (out,
 						"%s",
 						refurl, dispurl);
+				col += strlen (tmpurl);
 				g_free (tmpurl);
 				g_free (refurl);
 				g_free (dispurl);
@@ -179,6 +184,7 @@ e_text_to_html (const char *input, unsigned int flags)
 				  end - cur + 10);
 		memcpy (out, cur, end - cur);
 		out += end - cur;
+		col += end - cur;
 
 		if (!*end)
 			break;
@@ -188,37 +194,55 @@ e_text_to_html (const char *input, unsigned int flags)
 		case '<':
 			strcpy (out, "<");
 			out += 4;
+			col++;
 			break;
 
 		case '>':
 			strcpy (out, ">");
 			out += 4;
+			col++;
 			break;
 
 		case '&':
 			strcpy (out, "&");
 			out += 5;
+			col++;
 			break;
 
 		case '"':
 			strcpy (out, """);
 			out += 6;
+			col++;
 			break;
 
 		case '\n':
-			*out++ = *cur;
 			if (flags & E_TEXT_TO_HTML_CONVERT_NL) {
 				strcpy (out, "
"); out += 4; } + *out++ = *cur; + col = 0; break; + case '\t': + if (flags & (E_TEXT_TO_HTML_CONVERT_SPACES | + E_TEXT_TO_HTML_CONVERT_NL)) { + do { + strcpy (out, " "); + out += 6; + col++; + } while (col % 8); + break; + } + /* otherwise, FALL THROUGH */ + case ' ': if (flags & E_TEXT_TO_HTML_CONVERT_SPACES) { if (cur == (const unsigned char *)input || - *(cur + 1) == ' ') { + *(cur + 1) == ' ' || *(cur + 1) == '\t') { strcpy (out, " "); out += 6; + col++; break; } } @@ -231,6 +255,7 @@ e_text_to_html (const char *input, unsigned int flags) *out++ = *cur; } else out += g_snprintf(out, 9, "&#%d;", *cur); + col++; break; } -- cgit