gitee.com/quant1x/gox@v1.7.6/text/encoding/fallback.go (about) 1 package encoding 2 3 // FallbackDecoder combines a series of Decoders into one. 4 // If the first Decoder returns a status of INVALID_CHAR, the others are tried as well. 5 // 6 // Note: if the text to be decoded ends with a sequence of bytes that is not a valid character in the first charset, 7 // but it could be the beginning of a valid character, the FallbackDecoder will give a status of NO_ROOM instead of 8 // falling back to the other Decoders. 9 func FallbackDecoder(decoders ...Decoder) Decoder { 10 return func(p []byte) (c rune, size int, status Status) { 11 for _, d := range decoders { 12 c, size, status = d(p) 13 if status != INVALID_CHAR { 14 return 15 } 16 } 17 return 0, 1, INVALID_CHAR 18 } 19 }