-int
-html_strlen(const char *cp)
-{
- size_t rsz;
- int skip, sz;
-
- /*
- * Account for escaped sequences within string length
- * calculations. This follows the logic in term_strlen() as we
- * must calculate the width of produced strings.
- * Assume that characters are always width of "1". This is
- * hacky, but it gets the job done for approximation of widths.
- */
-
- sz = 0;
- skip = 0;
- while (1) {
- rsz = strcspn(cp, "\\");
- if (rsz) {
- cp += rsz;
- if (skip) {
- skip = 0;
- rsz--;
- }
- sz += rsz;
- }
- if ('\0' == *cp)
- break;
- cp++;
- switch (mandoc_escape(&cp, NULL, NULL)) {
- case ESCAPE_ERROR:
- return sz;
- case ESCAPE_UNICODE:
- case ESCAPE_NUMBERED:
- case ESCAPE_SPECIAL:
- case ESCAPE_OVERSTRIKE:
- if (skip)
- skip = 0;
- else
- sz++;
- break;
- case ESCAPE_SKIPCHAR:
- skip = 1;
- break;
- default:
- break;
- }
- }
- return sz;
-}
-