What is Nostr?
Doug Hoyte /
npub1yxp…qud4
2024-12-20 18:13:07
in reply to nevent1q…20mt

Doug Hoyte on Nostr: Is there an easy way to truncate to a max byte-length using the Go standard library? ...

Is there an easy way to truncate to a max byte-length using the Go standard library? This is the best answer I could find (after only 1 minute of searching though):

https://stackoverflow.com/questions/46415894/golang-truncate-strings-with-special-characters-without-corrupting-data/76502408#76502408

Note that as the answer says, this doesn't understand grapheme clusters, meaning that café can become cafe (depending on normalisation form). Also it involves another pass over the data which, if already known to be UTF-8, is redundant.

This 3rd party package looks to be the rough equivalent of my Perl module: https://github.com/rivo/uniseg
Author Public Key
npub1yxprsscnjw2e6myxz73mmzvnqw5kvzd5ffjya9ecjypc5l0gvgksh8qud4