TerryCavanagh / VVVVVV

The source code to VVVVVV! http://thelettervsixtim.es/
Other
7k stars 559 forks source link

Add new UTF-8 library, remove utfcpp submodule, fix UTF-8 fixme in next_wrap() #932

Closed Daaaav closed 1 year ago

Daaaav commented 1 year ago

Changes:

This adds a small library I wrote to handle UTF-8.

Usage is meant to be as simple as possible - see for example decoding a UTF-8 string:

const char* str = "asdf";
uint32_t codepoint;
while ((codepoint = UTF8_next(&str)))
{
    // you have a codepoint congrats
}

Or encoding a single codepoint to add it to a string:

std::string result;
result.append(UTF8_encode(0x1234).bytes);

There are some other functions (UTF8_total_codepoints() to get the total number of codepoints in a string, UTF8_backspace() to get the length of a string after backspacing one character, and UTF8_peek_next() as a slightly less fancy version of UTF8_next()), but more functions could always be added if we need them.

This allows us to replace utfcpp (utf8::unchecked) - which is also done in this PR - and also fix some less-than-ideal code:

The reason why I'm doing this now is also because my next button glyphs PR will most likely need it to encode the characters used for the button glyphs (and because next_wrap being incomplete might matter for localization).

Legal Stuff:

By submitting this pull request, I confirm that...