You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
691 B

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