fix bug in bytes.Map and add test cases for Map in both strings and bytes packages.

thanks to ulrik.sverdrup for the test case.

Fixes #191.

R=rsc
CC=golang-dev
https://golang.org/cl/155056
This commit is contained in:
Rob Pike 2009-11-15 12:07:27 -08:00
parent 13ad5d40c4
commit 27779dd6cb
3 changed files with 56 additions and 3 deletions

View file

@ -220,9 +220,7 @@ func Map(mapping func(rune int) int, s []byte) []byte {
for i := 0; i < len(s); {
wid := 1;
rune := int(s[i]);
if rune < utf8.RuneSelf {
rune = mapping(rune)
} else {
if rune >= utf8.RuneSelf {
rune, wid = utf8.DecodeRune(s[i:len(s)])
}
rune = mapping(rune);