Should we have this?
Str.displayUtf8 : List U8 -> Str
...where if it encounters any invalid UTF-8 sequences, it replaces them with the Unicode Replacement Character?
it's needed for the Path API, but not sure if it would be helpful elsewhere too :thinking:
Maybe Str.sanitizeUtf8?
displayUtf8 feels like it's just joining the utf-8 together
Not sure about the name, but I like the function :)
This would be great
Rust sometimes calls this fromUtf8Lossy but I don't like that because it sounds like it's always going to lose something (like lossy JPEG compression) but that's not really what's happening here
It does lose something
It loses any character that isn't valid utf8
So if you go back to utf8 from that string, you will have lost information. And instead have the urf8 replacement character
I definitely think this API should be fromUtf8Something to make it discoverable.
You could make it fromUtf8WithReplacement if you want to be really explicit.
Brendan Hansknecht said:
It does lose something
It loses any character that isn't valid utf8
yeah I just think of "lossy" meaning "you can expect it to lose something" whereas this is more "in very rare edge cases it can lose something"
Str.fromBytesReplaceInvalidUtf8
Last updated: Jun 16 2026 at 16:19 UTC