2 ms·
And what is wrong with an invalid UTF-8 string? Why were you truncating the string in the first place? Basically, I believe the point here is that a Unicode aw
by tsimionescu 6y ago
And what is wrong with an invalid UTF-8 string? Why were you truncating the string in the first place?
Basically, I believe the point here is that a Unicode aware truncation should be done in a Unicode aware truncate method. There is no good reason to parse a string as UTF-8 ahead of time - just keep it as a blob of bytes until you need to do some something "texty" with it. It is the truncate-at-word-boundaries() method that should interpret the bytes as UTF-8 and fail if they are not valid. Why parse it sooner?