func (s *Scanner) Scan(str string) (*UserAgent, error) {
	return s.ScanBytes([]byte(str))
}
Scan scans a user agent string for device information.
package agency
import (
	"bytes"
	"errors"
	"unicode"
	"unicode/utf8"
)
var errEOF = errors.New("eof")
type Scanner struct {
	c         rune
	buf       []byte
	buflen    int
	idx       int
	size      int
	prevstart int
	mobile    bool
	browsers  []*browser
	devices   []*device
	oses      []*aos
}
func NewScanner() *Scanner {
	return &Scanner{
		browsers: make([]*browser, maxRank),
		devices:  make([]*device, maxRank),
		oses:     make([]*aos, maxRank),
	}
}
func (s *Scanner) ScanBytes(b []byte) (*UserAgent, error) {
	var ua = new(UserAgent)
	s.buf = b
	s.buflen = len(b)
	s.reset()
	for {
		unigram, bigram, err := s.readNgrams()
		if err == errEOF {
			break
		} else if err != nil {
			return nil, err
		}
		if !s.mobile {
			s.matchMobile(unigram)
		}
		s.matchBrowser(unigram, bigram)
		s.matchDevice(unigram, bigram)
		s.matchOS(unigram, bigram)
	}
	for _, browser := range s.browsers {
		if browser != nil {
			ua.Browser.Type = browser.typ
			ua.Browser.Name = browser.name
			break
		}
	}
	for _, device := range s.devices {
		if device != nil {
			ua.Device.Type = device.typ
			break
		}
	}
	for _, os := range s.oses {
		if os != nil {
			ua.OS.Name = os.name
			ua.OS.Version = os.version
			break
		}
	}
	if s.mobile {
		if ua.Browser.Name == "Firefox" {
			ua.Browser.Type = "Mobile Browser"
			ua.Browser.Name = "Mobile Firefox"
		} else if ua.Browser.Name == "Safari" {
			ua.Browser.Type = "Mobile Browser"
			ua.Browser.Name = "Mobile Safari"
		} else if ua.Browser.Name == "Opera" {
			ua.Browser.Type = "Mobile Browser"
			ua.Browser.Name = "Opera Mobile"
		} else if ua.Browser.Name == "Yandex.Browser" {
			ua.Browser.Type = "Mobile Browser"
			ua.Browser.Name = "Yandex.Browser mobile"
		}
	}
	return ua, nil
}