diff options
| author | Mattias Andrée <m@maandree.se> | 2026-01-24 14:39:44 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-01-24 14:39:44 +0100 |
| commit | d554a18e5f981ae200f7f8a3e46d5da93190e897 (patch) | |
| tree | 99907dc58e28160b3814a901656f2d915b32e229 /libcharconv_replacement.c | |
| parent | First commit (diff) | |
| download | charconv-d554a18e5f981ae200f7f8a3e46d5da93190e897.tar.gz charconv-d554a18e5f981ae200f7f8a3e46d5da93190e897.tar.bz2 charconv-d554a18e5f981ae200f7f8a3e46d5da93190e897.tar.xz | |
Add replacement
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libcharconv_replacement.c')
| -rw-r--r-- | libcharconv_replacement.c | 42 |
1 files changed, 42 insertions, 0 deletions
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 <strings.h> + + +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; +} |
