[2553] in BarnOwl Developers
[PATCH 4/4] Consider format characters in owl_fmtext_num_lines
daemon@ATHENA.MIT.EDU (David Benjamin)
Sun Jul 25 17:57:12 2010
From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Sun, 25 Jul 2010 14:57:00 -0700
In-Reply-To: <1280095020-26263-1-git-send-email-davidben@mit.edu>
This fixes the second failure in the owl_fmtext test.
---
fmtext.c | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/fmtext.c b/fmtext.c
index d9d2993..04e470e 100644
--- a/fmtext.c
+++ b/fmtext.c
@@ -501,16 +501,26 @@ void owl_fmtext_truncate_cols(const owl_fmtext *in, int acol, int bcol, owl_fmte
int owl_fmtext_num_lines(const owl_fmtext *f)
{
int lines, i;
+ char *lastbreak, *p;
- if (f->textlen==0) return(0);
-
lines=0;
+ lastbreak = f->textbuff;
for (i=0; i<f->textlen; i++) {
- if (f->textbuff[i]=='\n') lines++;
+ if (f->textbuff[i]=='\n') {
+ lastbreak = f->textbuff + i;
+ lines++;
+ }
}
- /* if the last char wasn't a \n there's one more line */
- if (f->textbuff[i-1]!='\n') lines++;
+ /* Check if there's a trailing line; formatting characters don't count. */
+ for (p = g_utf8_next_char(lastbreak);
+ p < f->textbuff + f->textlen;
+ p = g_utf8_next_char(p)) {
+ if (!owl_fmtext_is_format_char(g_utf8_get_char(p))) {
+ lines++;
+ break;
+ }
+ }
return(lines);
}
--
1.7.2.rc2.1.gaace1