// EntityDecoder returns a Decoder that decodes HTML character entities.
// If there is no valid character entity at the current position, it returns INVALID_CHAR.
// So it needs to be combined with another Decoder via FallbackDecoder.
420397
func EntityDecoder() Decoder {
	var leftover rune // leftover rune from two-rune entity
	return func(p []byte) (r rune, size int, status Status) {
		if leftover != 0 {
			r = leftover
			leftover = 0
			return r, 0, SUCCESS
		}

		if len(p) == 0 {
			return 0, 0, NO_ROOM
		}

		if p[0] != '&' {
			return 0xfffd, 1, INVALID_CHAR
		}

		if len(p) < 3 {
			return 0, 1, NO_ROOM
		}

		r, size, status = 0xfffd, 1, INVALID_CHAR
		n := 1 // number of bytes read so far

		if p[n] == '#' {
			n++
			c := p[n]
			hex := false
			if c == 'x' || c == 'X' {
				hex = true
				n++
			}

			var x rune
			for n < len(p) {
				c = p[n]
				n++
				if hex {
					if '0' <= c && c <= '9' {
						x = 16*x + rune(c) - '0'
						continue
					} else if 'a' <= c && c <= 'f' {
						x = 16*x + rune(c) - 'a' + 10
						continue
					} else if 'A' <= c && c <= 'F' {
						x = 16*x + rune(c) - 'A' + 10
						continue
					}
				} else if '0' <= c && c <= '9' {
					x = 10*x + rune(c) - '0'
					continue
				}
				if c != ';' {
					n--
				}
				break
			}

			if n == len(p) && p[n-1] != ';' {
				return 0, 0, NO_ROOM
			}

			size = n
			if p[n-1] == ';' {
				n--
			}
			if hex {
				n--
			}
			n--
			// Now n is the number of actual digits read.
			if n == 0 {
				return 0xfffd, 1, INVALID_CHAR
			}

			if 0x80 <= x && x <= 0x9F {
				// Replace characters from Windows-1252 with UTF-8 equivalents.
				x = replacementTable[x-0x80]
			} else if x == 0 || (0xD800 <= x && x <= 0xDFFF) || x > 0x10FFFF {
				// Replace invalid characters with the replacement character.
				return 0xfffd, size, INVALID_CHAR
			}

			r = x
			status = SUCCESS
			return
		}

		// Look for a named entity in EntityList.

		possible := entityList
		for len(possible) > 0 {
			if len(p) <= n {
				leftover = 0
				return 0, 0, NO_ROOM
			}

			c := p[n]

			// Narrow down the selection in possible to those items that have c in the
			// appropriate byte.
			first := sort.Search(len(possible), func(i int) bool {
				e := possible[i].name
				if len(e) < n {
					return false
				}
				return e[n-1] >= c
			})
			possible = possible[first:]
			last := sort.Search(len(possible), func(i int) bool {
				return possible[i].name[n-1] > c
			})
			possible = possible[:last]

			n++
			if len(possible) > 0 && len(possible[0].name) == n-1 {
				r, leftover = possible[0].r1, possible[0].r2
				size = n
				status = SUCCESS
				// but don't return yet, since we need the longest match
			}
		}

		return
	}
}
1070257
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{
		called:   0,
		cursor:   0,
		keysDone: 0,
		err:      nil,
		r:        r,
		data:     make([]byte, 512),
		length:   0,
		isPooled: 0,
	}
}
1141112
func NewDecoder(config *DecoderConfig) (*Decoder, error) {
	val := reflect.ValueOf(config.Result)
	if val.Kind() != reflect.Ptr {
		return nil, errors.New("result must be a pointer")
	}

	val = val.Elem()
	if !val.CanAddr() {
		return nil, errors.New("result must be addressable (a pointer)")
	}

	if config.Metadata != nil {
		if config.Metadata.Keys == nil {
			config.Metadata.Keys = make([]string, 0)
		}

		if config.Metadata.Unused == nil {
			config.Metadata.Unused = make([]string, 0)
		}
	}

	if config.TagName == "" {
		config.TagName = "mapstructure"
	}

	result := &Decoder{
		config: config,
	}

	return result, nil
}
1209669
func (c *Charmap) NewDecoder() *encoding.Decoder {
	c.Init()
	return &encoding.Decoder{Transformer: &cmapDecoder{runes: c.runes}}
}
51269
func (s *Sling) ResponseDecoder(decoder ResponseDecoder) *Sling {
	if decoder == nil {
		return s
	}
	s.responseDecoder = decoder
	return s
}
1080752
func NewEncoder(w io.Writer) *Encoder {
	return &Encoder{w: w, escapeHTML: true}
}
1213421
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{Decoder: *json.NewDecoder(r)}
}
268156
func (u *UUID) decodeURN(t []byte) (err error) {
	total := len(t)

	urn_uuid_prefix := t[:9]

	if !bytes.Equal(urn_uuid_prefix, urnPrefix) {
		return fmt.Errorf("uuid: incorrect UUID format: %s", t)
	}

	return u.decodePlain(t[9:total])
}
162161
func NewDecoder(r io.Reader) goa.Decoder {
	return codec.NewDecoder(r, &Handle)
}
1179237
func (dec *mvccEntryDecoder) Decode(iter *Iterator) (bool, error) {
	ldec := lockDecoder{expectKey: dec.expectKey}
	ok, err := ldec.Decode(iter)
	if err != nil {
		return ok, errors.Trace(err)
	}
	if ok {
		dec.mvccEntry.lock = &ldec.lock
	}
	for iter.Valid() {
		vdec := valueDecoder{expectKey: dec.expectKey}
		ok, err = vdec.Decode(iter)
		if err != nil {
			return ok, errors.Trace(err)
		}
		if !ok {
			break
		}
		dec.mvccEntry.values = append(dec.mvccEntry.values, vdec.value)
	}
	succ := dec.mvccEntry.lock != nil || len(dec.mvccEntry.values) > 0
	return succ, nil
}
1141702
func DecodeString(src string) (body []byte, err error) {
	body, err = Encoding.DecodeString(src)
	return
}
484247
func NewDecoder(r io.Reader) Decoder {
	return Decoder{
		r:   r,
		buf: &bytes.Buffer{},
	}
}
438817
func NewDecoder(encodedAs EncodedAs, r io.Reader) Decoder {
	if encodedAs == EncodedAsJSON {
		return json.NewDecoder(r)
	} else if encodedAs == EncodedAsXML {
		return xml.NewDecoder(r)
	}
	return nil
}
354805
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{
		dec: codec.NewDecoder(r, new(codec.CborHandle)),
	}
}
325947
func NewDecoder(opts ...func(*Decoder)) *Decoder {
	d := &Decoder{
		MarshalOptions: MarshalOptions{
			SupportJSONTags: true,
		},
	}
	for _, o := range opts {
		o(d)
	}

	return d
}
1262857
func NewDecoder(s encoding.Source) encoding.Decoder {
	r := s()
	var (
		uf  = func(b []byte, m interface{}) error { return proto.Unmarshal(b, m.(proto.Message)) }
		dec = framing.NewDecoder(r, uf)
	)
	return encoding.DecoderFunc(func(u encoding.Unmarshaler) error { return dec.Decode(u) })
}
303949
func NewDecoder(decoder streaming.Decoder, embeddedDecoder runtime.Decoder) *Decoder {
	return &Decoder{
		decoder:         decoder,
		embeddedDecoder: embeddedDecoder,
	}
}