// ToLength forces the length of a []byte
488527
func ToLength(i []byte, rpl byte, length int) []byte {
	if len(i) == length {
		return i
	} else if len(i) > length {
		return i[:length]
	} else {
		var o = make([]byte, length)
		o = i
		for idx := 0; idx < length-len(i); idx++ {
			o = append(o, rpl)
		}
		return o
	}
}
322174
func (h *HTTPRangeSpec) GetLength(resourceSize int64) (rangeLength int64, err error) {
	switch {
	case resourceSize < 0:
		return 0, errors.New("Resource size cannot be negative")

	case h == nil:
		rangeLength = resourceSize

	case h.IsSuffixLength:
		specifiedLen := -h.Start
		rangeLength = specifiedLen
		if specifiedLen > resourceSize {
			rangeLength = resourceSize
		}

	case h.Start >= resourceSize:
		return 0, errInvalidRange

	case h.End > -1:
		end := h.End
		if resourceSize <= end {
			end = resourceSize - 1
		}
		rangeLength = end - h.Start + 1

	case h.End == -1:
		rangeLength = resourceSize - h.Start

	default:
		return 0, errors.New("Unexpected range specification case")
	}

	return rangeLength, nil
}
736550
func (f *NewConnectionIDFrame) Length(protocol.VersionNumber) protocol.ByteCount {
	return 1 + utils.VarIntLen(f.SequenceNumber) + 1 /* connection ID length */ + protocol.ByteCount(f.ConnectionID.Len()) + 16
}
347695
func truncateWithLength(source string, length int) string {
	if len(source) < length {
		return source
	}
	return source[:length]
}
1101026
func readLength(r io.Reader) (length int64, isPartial bool, err error) {
	var buf [4]byte
	_, err = readFull(r, buf[:1])
	if err != nil {
		return
	}
	switch {
	case buf[0] < 192:
		length = int64(buf[0])
	case buf[0] < 224:
		length = int64(buf[0]-192) << 8
		_, err = readFull(r, buf[0:1])
		if err != nil {
			return
		}
		length += int64(buf[0]) + 192
	case buf[0] < 255:
		length = int64(1) << (buf[0] & 0x1f)
		isPartial = true
	default:
		_, err = readFull(r, buf[0:4])
		if err != nil {
			return
		}
		length = int64(buf[0])<<24 |
			int64(buf[1])<<16 |
			int64(buf[2])<<8 |
			int64(buf[3])
	}
	return
}
1183471
func (b *base) appendRemainingLength() {
	// Calculate and encode the Remaining Length.
	rl := encodeLength(uint32(len(b.variableHeader) + len(b.payload)))

	// Append the Remaining Length to the fixed header.
	b.fixedHeader = appendRemainingLength(b.fixedHeader, rl)
}
1358583
func (d *Disque) QueueLength(queueName string) (queueLength int, err error) {
	return redis.Int(d.call("QLEN", redis.Args{}.Add(queueName)))
}
567404
func ContentLength(l int64) RequestOption {
	return func(req *http.Request) (*http.Request, error) {
		if l >= 0 {
			req.ContentLength = l
		}
		return req, nil
	}
}
964525
func Length(collection cty.Value) (cty.Value, error) {
	return LengthFunc.Call([]cty.Value{collection})
}
852471
func ContentLength(h http.Header, size int64) {
	h.Set(HeaderContentLength, strconv.FormatInt(size, 10))
}
395379
func MinLength(val int) {
	if a, ok := attributeDefinition(); ok {
		if a.Type != nil && a.Type.Kind() != design.StringKind && a.Type.Kind() != design.ArrayKind && a.Type.Kind() != design.HashKind {
			incompatibleAttributeType("minimum length", a.Type.Name(), "a string or an array")
		} else {
			if a.Validation == nil {
				a.Validation = &dslengine.ValidationDefinition{}
			}
			a.Validation.MinLength = &val
		}
	}
}
384362
func (s *Scanner) readLength(first byte) (int64, error) {
	length := int64(first & maskFirstLength)

	c := first
	shift := firstLengthBits
	var err error
	for c&maskContinue > 0 {
		if c, err = s.r.ReadByte(); err != nil {
			return 0, err
		}

		length += int64(c&maskLength) << shift
		shift += lengthBits
	}

	return length, nil
}
1231729
func (rd *RAMDirectory) FileLength(name string) (length int64, err error) {
	rd.EnsureOpen()
	rd.fileMapLock.RLock()
	defer rd.fileMapLock.RUnlock()
	if file, ok := rd.fileMap[name]; ok {
		return file.Length(), nil
	}
	return 0, os.ErrNotExist
}
352841
func UTF16Length(str string) (n int) {
	length := len(str)
	n = length
	p := 0
	for p < length {
		a := str[p]
		switch a >> 4 {
		case 0, 1, 2, 3, 4, 5, 6, 7:
			p++
		case 12, 13:
			p += 2
			n--
		case 14:
			p += 3
			n -= 2
		case 15:
			if a&8 == 8 {
				return -1
			}
			p += 4
			n -= 2
		default:
			return -1
		}
	}
	return n
}
1109700
func (s *Certificate) SetKeyLength(v int64) *Certificate {
	s.KeyLength = &v
	return s
}
574064
func MaxLength(path, in, data string, maxLength int64) *errors.Validation {
	strLen := int64(utf8.RuneCount([]byte(data)))
	if strLen > maxLength {
		return errors.TooLong(path, in, maxLength)
	}
	return nil
}
136397
func (r *Rows) ColumnTypeLength(index int) (int64, bool) {
	return r.rows.FieldDescriptions()[index].Length()
}