bytes, strings: allow -1 in Map to mean "drop this character".

xml: drop invalid characters in attribute names
    when constructing struct field names.

R=rsc
CC=r
https://golang.org/cl/157104
This commit is contained in:
Kei Son 2009-12-11 10:37:48 -08:00 committed by Russ Cox
parent 67aa1399d6
commit 128974adfd
6 changed files with 91 additions and 26 deletions

View file

@ -365,6 +365,19 @@ func TestMap(t *testing.T) {
if string(m) != expect {
t.Errorf("rot13: expected %q got %q", expect, m)
}
// 5. Drop
dropNotLatin := func(rune int) int {
if unicode.Is(unicode.Latin, rune) {
return rune
}
return -1;
};
m = Map(dropNotLatin, Bytes("Hello, 세계"));
expect = "Hello";
if string(m) != expect {
t.Errorf("drop: expected %q got %q", expect, m)
}
}
func TestToUpper(t *testing.T) { runStringTests(t, ToUpper, "ToUpper", upperTests) }