blob: a9bd3c57cdd67aca27d192913c2046fd87216f1a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
}
|