From 25d6ae69d1cb392922b9d9dc0da1c17aef9a9db2 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 7 Sep 2014 19:58:01 -0400 Subject: Remove hg dep --- modules/mahonia/fallback.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 modules/mahonia/fallback.go (limited to 'modules/mahonia/fallback.go') diff --git a/modules/mahonia/fallback.go b/modules/mahonia/fallback.go new file mode 100644 index 00000000..27259c5d --- /dev/null +++ b/modules/mahonia/fallback.go @@ -0,0 +1,19 @@ +package mahonia + +// FallbackDecoder combines a series of Decoders into one. +// If the first Decoder returns a status of INVALID_CHAR, the others are tried as well. +// +// Note: if the text to be decoded ends with a sequence of bytes that is not a valid character in the first charset, +// but it could be the beginning of a valid character, the FallbackDecoder will give a status of NO_ROOM instead of +// falling back to the other Decoders. +func FallbackDecoder(decoders ...Decoder) Decoder { + return func(p []byte) (c rune, size int, status Status) { + for _, d := range decoders { + c, size, status = d(p) + if status != INVALID_CHAR { + return + } + } + return 0, 1, INVALID_CHAR + } +} -- cgit v1.2.3