sheredom / utf8.h

📚 single header utf8 string functions for C and C++
The Unlicense
1.69k stars 123 forks source link

Request for utf8makevalid() function in addition to utf8valid() #75

Closed jjn555 closed 3 years ago

jjn555 commented 3 years ago

A common use case is that an application has to somehow work with the string provided even if it may have invalid sequences. This function would replace invalid utf8 sequences in a string with the specified valid utf8 character byte, ensuring that the output is valid utf8 and has the same total byte length as the input.

sheredom commented 3 years ago

I don't quite understand how this would look - but I'm not against the idea in principle. Would be happy to accept a PR for this!

jjn555 commented 3 years ago

This would be similar to what is implemented as utf8::replace_invalid() in this open source utf8 library: https://github.com/nemtrif/utfcpp