* all:
[modest] / src / modest-text-utils.c
index 3039ced..c43475e 100644 (file)
@@ -36,23 +36,37 @@ get_breakpoint(const gchar *s, const gint indent, const gint limit);
 static GString *
 get_next_line(GtkTextBuffer *b, GtkTextIter *iter)
 {
-       GtkTextIter iter2;
+       GtkTextIter iter2, iter3;
        gchar *tmp;
+       GString *line;
+       
+       if (gtk_text_iter_is_end(iter))
+               return g_string_new("");
        
        gtk_text_buffer_get_iter_at_line_offset(b,
                        &iter2,
                        gtk_text_iter_get_line(iter),
-                       gtk_text_iter_get_chars_in_line(iter) -1
+                       gtk_text_iter_get_chars_in_line(iter) - 1
                );
-       tmp = gtk_text_buffer_get_text(b, &iter2, iter, FALSE);
+       iter3 = iter2;
+       gtk_text_iter_forward_char(&iter2);
+       if (gtk_text_iter_is_end(&iter2)) {
+               tmp = gtk_text_buffer_get_text(b, &iter2, iter, FALSE);
+       } else {
+               tmp = gtk_text_buffer_get_text(b, &iter3, iter, FALSE);
+       }
+       line = g_string_new(tmp);
+               
        gtk_text_iter_forward_line(iter);
-       return g_string_new(tmp);
+       
+       return line;
 }
 
 static int
 get_indent_level(const char *l)
 {
        int indent = 0;
+       
        while (l[0]) {
                if (l[0] == '>') {
                        indent++;
@@ -65,7 +79,15 @@ get_indent_level(const char *l)
                l++;
                
        }
-       return indent;
+
+       /*      if we hit the signature marker "-- ", we return -(indent + 1). This
+       *       stops reformatting.
+       */
+       if (strcmp(l, "-- ") == 0) {
+               return -1-indent;
+       } else {
+               return indent;
+       }
 }
 
 static void
@@ -88,9 +110,10 @@ unquote_line(GString *l) {
 }
 
 static void
-append_quoted(GString *buf, const int indent, const GString *str, const int cutpoint) {
+append_quoted(GString *buf, int indent, const GString *str, const int cutpoint) {
        int i;
        
+       indent = indent < 0? abs(indent) -1 : indent;
        for (i=0; i<=indent; i++) {
                g_string_append(buf, "> ");
        }
@@ -103,11 +126,13 @@ append_quoted(GString *buf, const int indent, const GString *str, const int cutp
 }
 
 static int
-get_breakpoint_utf8(const gchar *s, const gint indent, const gint limit) {
+get_breakpoint_utf8(const gchar *s, gint indent, const gint limit) {
        gint index = 0;
        const gchar *pos, *last;
        gunichar *uni;
        
+       indent = indent < 0? abs(indent) -1 : indent;
+       
        last = NULL;
        pos = s;
        uni = g_utf8_to_ucs4_fast(s, -1, NULL);
@@ -123,7 +148,7 @@ get_breakpoint_utf8(const gchar *s, const gint indent, const gint limit) {
                index++;
        }
        g_free(uni);
-       return index;
+       return strlen(s);
 }
 
 static int
@@ -203,7 +228,7 @@ modest_text_utils_quote(GtkTextBuffer *buf, const gchar *from, const time_t sent
                rem_indent = indent;
                append_quoted(q, indent, l, breakpoint);
                g_string_free(l, TRUE);
-       } while (!gtk_text_iter_is_end(&iter));
+       } while (remaining->str[0] || !gtk_text_iter_is_end(&iter));
        
        return g_string_free(q, FALSE);
 }