1 #include <assert.h>
2 
3 #include <libnu/casemap.h>
4 
5 #ifdef NU_WITH_TOLOWER
6 
7 #include <libnu/casemap_internal.h>
8 #include "gen/_tolower.c"
9 
10 /* in nu_casemap_read (UTF-8), zero-terminated */
11 static const char *__nu_final_sigma = "ς";
12 
nu_tolower(uint32_t codepoint)13 const char* nu_tolower(uint32_t codepoint) {
14 	return _nu_to_something(codepoint, NU_TOLOWER_G, NU_TOLOWER_G_SIZE,
15 		NU_TOLOWER_VALUES_C, NU_TOLOWER_VALUES_I, NU_TOLOWER_COMBINED);
16 }
17 
_nu_tolower(const char * encoded,const char * limit,nu_read_iterator_t read,uint32_t * u,const char ** transform,void * context)18 const char* _nu_tolower(const char *encoded, const char *limit, nu_read_iterator_t read,
19 	uint32_t *u, const char **transform,
20 	void *context) {
21 
22 	(void)(context);
23 
24 	uint32_t _u = 0;
25 	const char *np = read(encoded, &_u);
26 
27 	if (u != 0) {
28 		*u = _u;
29 	}
30 
31 	/* handling of 0x03A3 ('Σ')
32 	 *
33 	 * this is the only language-independent exception described in
34 	 * SpecialCasing.txt (Unicode 7.0) */
35 
36 	assert(nu_casemap_read == nu_utf8_read);
37 
38 	if (_u == 0x03A3) {
39 		if (np >= limit) {
40 			*transform = __nu_final_sigma;
41 			return np;
42 		}
43 
44 		uint32_t nu = 0;
45 		read(np, &nu);
46 
47 		if (nu == 0) {
48 			*transform = __nu_final_sigma;
49 			return np;
50 		}
51 	}
52 
53 	*transform = nu_tolower(_u);
54 
55 	return np;
56 }
57 
58 #endif /* NU_WITH_TOLOWER */
59