source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Use strcspn() in term_strlen().
@ 2011-05-15 14:50 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-05-15 14:50 UTC (permalink / raw)
  To: source

Log Message:
-----------
Use strcspn() in term_strlen().  Clarifies the code.

Modified Files:
--------------
    mdocml:
        term.c

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.188
retrieving revision 1.189
diff -Lterm.c -Lterm.c -u -p -r1.188 -r1.189
--- term.c
+++ term.c
@@ -606,8 +606,8 @@ term_strlen(const struct termp *p, const
 {
 	size_t		 sz, rsz, i;
 	int		 ssz;
-	enum mandoc_esc	 esc;
 	const char	*seq, *rhs;
+	static const char rej[] = { '\\', ASCII_HYPH, ASCII_NBRSP, '\0' };
 
 	/*
 	 * Account for escaped sequences within string length
@@ -616,15 +616,17 @@ term_strlen(const struct termp *p, const
 	 */
 
 	sz = 0;
-	while ('\0' != *cp)
+	while ('\0' != *cp) {
+		rsz = strcspn(cp, rej);
+		for (i = 0; i < rsz; i++)
+			sz += (*p->width)(p, *cp++);
+
 		switch (*cp) {
 		case ('\\'):
-			++cp;
-			esc = mandoc_escape(&cp, &seq, &ssz);
-			if (ESCAPE_ERROR == esc)
+			cp++;
+			switch (mandoc_escape(&cp, &seq, &ssz)) {
+			case (ESCAPE_ERROR):
 				return(sz);
-
-			switch (esc) {
 			case (ESCAPE_PREDEF):
 				rhs = mchars_res2str
 					(p->symtab, seq, ssz, &rsz);
@@ -659,14 +661,13 @@ term_strlen(const struct termp *p, const
 			cp++;
 			break;
 		default:
-			sz += (*p->width)(p, *cp++);
 			break;
 		}
+	}
 
 	return(sz);
 }
 
-
 /* ARGSUSED */
 size_t
 term_vspan(const struct termp *p, const struct roffsu *su)
@@ -702,7 +703,6 @@ term_vspan(const struct termp *p, const 
 	return(/* LINTED */(size_t)
 			r);
 }
-
 
 size_t
 term_hspan(const struct termp *p, const struct roffsu *su)
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-15 14:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-15 14:50 mdocml: Use strcspn() in term_strlen() kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).