aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/term.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-05-15 14:50:01 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-05-15 14:50:01 +0000
commit4dc1b5414a1d1531b0c9a1b0061792b0076e329a (patch)
tree45b6af3a5fedf4d89f1deb3ee6604923f39afd88 /term.c
parent5f23528a79ea675183cb4f4b0975bbef370227d0 (diff)
downloadmandoc-4dc1b5414a1d1531b0c9a1b0061792b0076e329a.tar.gz
mandoc-4dc1b5414a1d1531b0c9a1b0061792b0076e329a.tar.zst
mandoc-4dc1b5414a1d1531b0c9a1b0061792b0076e329a.zip
Use strcspn() in term_strlen(). Clarifies the code.
Diffstat (limited to 'term.c')
-rw-r--r--term.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/term.c b/term.c
index 92a67377..1c5e8ff0 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.188 2011/05/14 18:15:20 kristaps Exp $ */
+/* $Id: term.c,v 1.189 2011/05/15 14:50:01 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -606,8 +606,8 @@ term_strlen(const struct termp *p, const char *cp)
{
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 char *cp)
*/
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 char *cp)
cp++;
break;
default:
- sz += (*p->width)(p, *cp++);
break;
}
+ }
return(sz);
}
-
/* ARGSUSED */
size_t
term_vspan(const struct termp *p, const struct roffsu *su)
@@ -703,7 +704,6 @@ term_vspan(const struct termp *p, const struct roffsu *su)
r);
}
-
size_t
term_hspan(const struct termp *p, const struct roffsu *su)
{