Counting a decorated line
A line-drawing function prints a start string, enough horizontal bars to reach a target length, and an end string. It calls mbsrlen for the start and end: strlen would count bytes, not the characters represented by those bytes. section 14.3
A multibyte character is a sequence of bytes interpreted as one character in an extended character set. A multibyte string contains such characters. Its characters contain no null bytes, and the string remains null terminated, so byte-oriented operations such as strcpy still work. section 14.3
TAKEAWAY: String compatibility does not make byte length a character count. Call setlocale before printing extended characters; otherwise terminal output may be wrong. For character counting, mbsrlen interprets the string as wide characters and reports an encoding error with -1. Parsing individual characters may also require a consistent conversion state. section 14.3
void draw_sep(char const start[static 1], char const end[static 1]) { fputs(start, stdout); size_t slen = mbsrlen(start, 0); size_t elen = 90 - mbsrlen(end, 0); for (size_t i = slen; i < elen; ++i) fputs(HBAR, stdout); fputs(end, stdout); fputc('\n', stdout); } !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":4}],[{\"line\":0,\"ch\":14},{\"line\":0,\"ch\":24}],[{\"line\":1,\"ch\":16},{\"line\":1,\"ch\":26}],[{\"line\":0,\"ch\":31},{\"line\":0,\"ch\":37}],[{\"line\":1,\"ch\":31},{\"line\":1,\"ch\":37}],[{\"line\":0,\"ch\":14},{\"line\":0,\"ch\":24}],[{\"line\":1,\"ch\":16},{\"line\":1,\"ch\":26}],[{\"line\":0,\"ch\":31},{\"line\":0,\"ch\":37}],[{\"line\":1,\"ch\":31},{\"line\":1,\"ch\":37}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":9}],[{\"line\":5,\"ch\":41},{\"line\":5,\"ch\":46}],[{\"line\":6,\"ch\":4},{\"line\":6,\"ch\":9}],[{\"line\":2,\"ch\":17},{\"line\":2,\"ch\":23}],[{\"line\":5,\"ch\":53},{\"line\":5,\"ch\":59}],[{\"line\":6,\"ch\":15},{\"line\":6,\"ch\":21}],[{\"line\":7,\"ch\":16},{\"line\":7,\"ch\":22}],[{\"line\":3,\"ch\":4},{\"line\":3,\"ch\":10}],[{\"line\":4,\"ch\":4},{\"line\":4,\"ch\":10}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":15}],[{\"line\":3,\"ch\":4},{\"line\":3,\"ch\":10}],[{\"line\":4,\"ch\":4},{\"line\":4,\"ch\":10}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":15}],[{\"line\":5,\"ch\":4},{\"line\":5,\"ch\":7}],[{\"line\":3,\"ch\":4},{\"line\":3,\"ch\":10}],[{\"line\":4,\"ch\":4},{\"line\":4,\"ch\":10}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":15}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":9}],[{\"line\":5,\"ch\":41},{\"line\":5,\"ch\":46}],[{\"line\":6,\"ch\":4},{\"line\":6,\"ch\":9}],[{\"line\":2,\"ch\":17},{\"line\":2,\"ch\":23}],[{\"line\":5,\"ch\":53},{\"line\":5,\"ch\":59}],[{\"line\":6,\"ch\":15},{\"line\":6,\"ch\":21}],[{\"line\":7,\"ch\":16},{\"line\":7,\"ch\":22}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":9}],[{\"line\":5,\"ch\":41},{\"line\":5,\"ch\":46}],[{\"line\":6,\"ch\":4},{\"line\":6,\"ch\":9}],[{\"line\":2,\"ch\":17},{\"line\":2,\"ch\":23}],[{\"line\":5,\"ch\":53},{\"line\":5,\"ch\":59}],[{\"line\":6,\"ch\":15},{\"line\":6,\"ch\":21}],[{\"line\":7,\"ch\":16},{\"line\":7,\"ch\":22}],[{\"line\":7,\"ch\":4},{\"line\":7,\"ch\":9}],[{\"line\":2,\"ch\":17},{\"line\":2,\"ch\":23}],[{\"line\":5,\"ch\":53},{\"line\":5,\"ch\":59}],[{\"line\":6,\"ch\":15},{\"line\":6,\"ch\":21}],[{\"line\":7,\"ch\":16},{\"line\":7,\"ch\":22}]]"} !@%STYLE%@!
The draw_sep implementation shows mbsrlen used to choose how many horizontal bars to print. section 14.3

