aboutsummaryrefslogtreecommitdiff
path: root/include/mglpp/system/Utf8.hpp
blob: ba1b90ed32d72b7576049414d379c317ab9fc59e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef MGLPP_UTF8_HPP
#define MGLPP_UTF8_HPP

#include <stddef.h>
#include <stdint.h>

namespace mgl {
    // Returns false on failure. |decoded_codepoint| is set to |str[0]| if size > 0 and |codepoint_length| is set to 1
    bool utf8_decode(const unsigned char *str, size_t size, uint32_t *decoded_codepoint, size_t *codepoint_length);
    /*
        |str| should be the start of the utf8 string and |size| is the size of the string.
        Returns the index of the start of the codepoint that starts at or before |offset|,
        or if the string contains invalid utf8 then the index to the invalid character is returned.
        Returns 0 if start of codepoint is not found.
    */
    size_t utf8_get_start_of_codepoint(const unsigned char *str, size_t size, size_t offset);
}

#endif /* MGLPP_UTF8_HPP */