diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-20 00:18:15 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-20 00:18:15 +0000 |
commit | 84911de8492fb75007eec6bfa4abb7905439f93c (patch) | |
tree | c891bdec1e6f073f73fedeef23718bc3ac30d499 /libgo/go/image/format.go | |
parent | ad33e6a8510b48571eaef50af339892925108830 (diff) | |
download | gcc-84911de8492fb75007eec6bfa4abb7905439f93c.tar.gz |
Update to current version of Go library.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@173931 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/image/format.go')
-rw-r--r-- | libgo/go/image/format.go | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/libgo/go/image/format.go b/libgo/go/image/format.go index 1d541b09406..b4859325e1d 100644 --- a/libgo/go/image/format.go +++ b/libgo/go/image/format.go @@ -25,7 +25,8 @@ var formats []format // RegisterFormat registers an image format for use by Decode. // Name is the name of the format, like "jpeg" or "png". -// Magic is the magic prefix that identifies the format's encoding. +// Magic is the magic prefix that identifies the format's encoding. The magic +// string can contain "?" wildcards that each match any one byte. // Decode is the function that decodes the encoded image. // DecodeConfig is the function that decodes just its configuration. func RegisterFormat(name, magic string, decode func(io.Reader) (Image, os.Error), decodeConfig func(io.Reader) (Config, os.Error)) { @@ -46,11 +47,24 @@ func asReader(r io.Reader) reader { return bufio.NewReader(r) } -// sniff determines the format of r's data. +// Match returns whether magic matches b. Magic may contain "?" wildcards. +func match(magic string, b []byte) bool { + if len(magic) != len(b) { + return false + } + for i, c := range b { + if magic[i] != c && magic[i] != '?' { + return false + } + } + return true +} + +// Sniff determines the format of r's data. func sniff(r reader) format { for _, f := range formats { - s, err := r.Peek(len(f.magic)) - if err == nil && string(s) == f.magic { + b, err := r.Peek(len(f.magic)) + if err == nil && match(f.magic, b) { return f } } |