From d554a18e5f981ae200f7f8a3e46d5da93190e897 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 24 Jan 2026 14:39:44 +0100 Subject: Add replacement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libcharconv_replacement.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libcharconv_replacement.c (limited to 'libcharconv_replacement.c') diff --git a/libcharconv_replacement.c b/libcharconv_replacement.c new file mode 100644 index 0000000..a9bd3c5 --- /dev/null +++ b/libcharconv_replacement.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "libcharconv.h" +#include + + +enum libcharconv_result +libcharconv_replacement(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp) +{ + uint_least32_t c; + *n = 0; + while (slen) { + if (slen < 3u && !strncasecmp(s, "obj", slen)) { + if (*n) + goto no_conv; + return LIBCHARCONV_INDETERMINATE; + } else if (slen >= 3u && !strncasecmp(s, "obj", 3u)) { + if (*n) + goto no_conv; + c = UINT32_C(0xFFFC); + *n = 3u; + goto conv; + } else if (*s == '?') { + if (*n) + goto no_conv; + c = UINT32_C(0xFFFD); + *n = 1u; + goto conv; + } else { + *n += 1u; + s++; + slen--; + } + } +no_conv: + return LIBCHARCONV_NO_CONVERT; + +conv: + if (*ncp) + *cp = c; + *ncp = 1u; + return LIBCHARCONV_CONVERTED; +} -- cgit v1.2.3-70-g09d2