On Nov 18, 12:29 pm, Adam Langley <
a...@golang.org> wrote:
> You can iterate over the code points in a string with:
> for byteIndex, codePoint := range s { ...
Thanks for the suggestion.
> Then you can use EncodeRune to write from the end of a newly allocated
> byte slice (of the same length as the string), backwards.
I am trying something like this:
package main
import "utf8";
func main () {
var dummy [5]byte;
input := "The quick brown 狐 jumped over the lazy 犬";
output := "";
for byteIndex, codePoint := range input {
n_bytes := utf8.EncodeRune (codePoint, dummy);
output = input[byteIndex:byteIndex + n_bytes] + output
}
print (output,"\n");
}
However, I don't see the syntax for how to declare "dummy" correctly.
I am just getting compiler errors or segmentation faults with
everything I try. Although this isn't the way you suggest, can someone
tell me how to declare dummy so that it works here?
> Of course, you'll still mangle the Unicode since combining characters
> and other code points should be reordered. Implementing the grapheme
> boundary algorithm is rather more involved.
Do other languages currently do that? It seems like it would involve
checking every character against a database.