diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-05-15 14:50:01 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-05-15 14:50:01 +0000 |
commit | 6ae46f238194f0cb76bd4e0b8dd456d2be0b960d (patch) | |
tree | 75b19d72633be10c6cbdf187347b5000be405235 /term.c | |
parent | 275f8a2331ee97d749bb993340b12e3651e41312 (diff) | |
download | mandoc-6ae46f238194f0cb76bd4e0b8dd456d2be0b960d.tar.gz |
Use strcspn() in term_strlen(). Clarifies the code.
Diffstat (limited to 'term.c')
-rw-r--r-- | term.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -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) { |