From b710c7eb580d8f291bee9bc760d806ec305f26b2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 25 Jan 2026 21:03:48 +0100 Subject: Add control character representations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libcharconv_control_characters.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'libcharconv_control_characters.c') diff --git a/libcharconv_control_characters.c b/libcharconv_control_characters.c index 55e4bbf..c45f03e 100644 --- a/libcharconv_control_characters.c +++ b/libcharconv_control_characters.c @@ -132,6 +132,21 @@ libcharconv_control_characters(const char *s, size_t slen, size_t *n, uint_least int indeterminate; *n = 0; for (; slen; s++, slen--, ++*n) { + if (s[0] == '\xE2') { + if (slen == 1u) + return LIBCHARCONV_INDETERMINATE; + if (s[1] != '\x90') + goto search; + if (slen == 2u) + return LIBCHARCONV_INDETERMINATE; + i = ((const unsigned char *)s)[2]; + if (0x80u > i || i > 0xA1u) + goto search; + i &= 0x3Fu; + i = i == 0x21u ? 0x7Fu : i; + goto conv_repr; + } + search: indeterminate = 0; found = SIZE_MAX; found_len = 0u; @@ -158,6 +173,15 @@ libcharconv_control_characters(const char *s, size_t slen, size_t *n, uint_least no_conv: return LIBCHARCONV_NO_CONVERT; +conv_repr: + if (*n) + goto no_conv; + if (*ncp) + *cp = (uint_least32_t)i; + *n += 3u; + *ncp = 1u; + return LIBCHARCONV_CONVERTED; + conv: if (*n) goto no_conv; -- cgit v1.2.3-70-g09d2