MCPcopy Index your code
hub / github.com/golang/text / ExampleUTF8Validator

Function ExampleUTF8Validator

encoding/example_test.go:26–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24}
25
26func ExampleUTF8Validator() {
27 for i := 0; i < 2; i++ {
28 var transformer transform.Transformer
29 transformer = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewEncoder()
30 if i == 1 {
31 transformer = transform.Chain(encoding.UTF8Validator, transformer)
32 }
33 dst := make([]byte, 256)
34 src := []byte("abc\xffxyz") // src is invalid UTF-8.
35 nDst, nSrc, err := transformer.Transform(dst, src, true)
36 fmt.Printf("i=%d: produced %q, consumed %q, error %v\n",
37 i, dst[:nDst], src[:nSrc], err)
38 }
39 // Output:
40 // i=0: produced "\x00a\x00b\x00c\xff\xfd\x00x\x00y\x00z", consumed "abc\xffxyz", error <nil>
41 // i=1: produced "\x00a\x00b\x00c", consumed "abc", error encoding: invalid UTF-8
42}

Callers

nothing calls this directly

Calls 5

TransformMethod · 0.95
UTF16Function · 0.92
ChainFunction · 0.92
NewEncoderMethod · 0.65
PrintfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…