1 | #include <mbgl/util/platform.hpp> |
2 | #include <libnu/unaccent.h> |
3 | #include <unaccent.hpp> |
4 | |
5 | #include <cstring> |
6 | #include <sstream> |
7 | |
8 | namespace mbgl { namespace platform { |
9 | |
10 | std::string unaccent(const std::string& str) |
11 | { |
12 | std::stringstream output; |
13 | char const *itr = str.c_str(), *nitr; |
14 | char const *end = itr + str.length(); |
15 | char lo[5] = { 0 }; |
16 | |
17 | for (; itr < end; itr = nitr) |
18 | { |
19 | uint32_t code_point = 0; |
20 | char const* buf = nullptr; |
21 | |
22 | nitr = _nu_tounaccent(encoded: itr, limit: end, read: nu_utf8_read, u: &code_point, transform: &buf, context: nullptr); |
23 | if (buf != nullptr) |
24 | { |
25 | do |
26 | { |
27 | buf = NU_CASEMAP_DECODING_FUNCTION(utf8: buf, unicode: &code_point); |
28 | if (code_point == 0) break; |
29 | output.write(s: lo, n: nu_utf8_write(unicode: code_point, utf8: lo) - lo); |
30 | } |
31 | while (code_point != 0); |
32 | } |
33 | else |
34 | { |
35 | output.write(s: itr, n: nitr - itr); |
36 | } |
37 | } |
38 | |
39 | return output.str(); |
40 | } |
41 | |
42 | } // namespace platform |
43 | } // namespace mbgl |
44 | |