// returns the number of bytes skipped and an error, in case the string is
// longer than the input slice
190415
func skipLengthEncodedString(b []byte) (int, error) {
	// Get length
	num, _, n := readLengthEncodedInteger(b)
	if num < 1 {
		return n, nil
	}

	n += int(num)

	// Check data length
	if len(b) >= n {
		return n, nil
	}
	return n, io.EOF
}
675760
func skipSpace(s string) (rest string) {
	i := 0
	for ; i < len(s); i++ {
		if b := s[i]; b != ' ' && b != '\t' {
			break
		}
	}
	return s[i:]
}
340091
func String(length int) string {
	return base64.RawStdEncoding.EncodeToString(Bytes(length))[:length]
}
1361418
func countIndents(input string) int {
	var (
		indents     = 0
		inString    = false
		strOpenChar = ' '   // keep track of the string open char to allow var str = "I'm ....";
		charEscaped = false // keep track if the previous char was the '\' char, allow var str = "abc\"def";
	)

	for _, c := range input {
		switch c {
		case '\\':
			// indicate next char as escaped when in string and previous char isn't escaping this backslash
			if !charEscaped && inString {
				charEscaped = true
			}
		case '\'', '"':
			if inString && !charEscaped && strOpenChar == c { // end string
				inString = false
			} else if !inString && !charEscaped { // begin string
				inString = true
				strOpenChar = c
			}
			charEscaped = false
		case '{', '(':
			if !inString { // ignore brackets when in string, allow var str = "a{"; without indenting
				indents++
			}
			charEscaped = false
		case '}', ')':
			if !inString {
				indents--
			}
			charEscaped = false
		default:
			charEscaped = false
		}
	}

	return indents
}
917819
func CountBytes(b []byte) (int, error) {
	var count int
	for len(b) >= 8 {
		v := binary.BigEndian.Uint64(b[:8])
		b = b[8:]

		sel := v >> 60
		if sel >= 16 {
			return 0, fmt.Errorf("invalid selector value: %v", sel)
		}
		count += selector[sel].n
	}

	if len(b) > 0 {
		return 0, fmt.Errorf("invalid slice len remaining: %v", len(b))
	}
	return count, nil
}
930507
func (tkn *Tokenizer) skipStatement() int {
	tkn.SkipToEnd = false
	for {
		typ, _ := tkn.Scan()
		if typ == 0 || typ == ';' || typ == LEX_ERROR {
			return typ
		}
	}
}
365700
func splitLength(s string, length int) []string {
	var ret []string

	for len(s) > 0 {
		tmp := truncateString(s, length)
		if len(tmp) == 0 {
			// too short length, or invalid UTF-8 string
			break
		}
		ret = append(ret, tmp)
		s = s[len(tmp):]
	}

	return ret
}
234751
func getlength(bs *BlockDriverState) (int64, error) {
	length, err := nbSectors(bs)
	if err != nil {
		return 0, err
	}

	if length > int64(INT64_MAX/BDRV_SECTOR_SIZE) {
		return 0, syscall.EFBIG
	}
	return length * int64(BDRV_SECTOR_SIZE), nil
}
191885
func (e ExecError) ShortError() string {
	outStr := e.truncateStr(e.StdOut, execShortErrorMaxLines)
	errStr := e.truncateStr(e.StdErr, execShortErrorMaxLines)
	return fmt.Sprintf(execErrorMsgFmt, e.Command, outStr, errStr)
}
747220
func (es MultiError) Error() string {
	var buf bytes.Buffer

	if len(es) > 1 {
		fmt.Fprintf(&buf, "%d errors: ", len(es))
	}

	for i, err := range es {
		if i != 0 {
			buf.WriteString("; ")
		}
		buf.WriteString(err.Error())
	}

	return buf.String()
}
901234
func string_count(fnname string, recv_ Value, args Tuple, kwargs []Tuple) (Value, error) {
	recv := string(recv_.(String))

	var sub string
	var start_, end_ Value
	if err := UnpackPositionalArgs(fnname, args, kwargs, 1, &sub, &start_, &end_); err != nil {
		return nil, err
	}

	start, end, err := indices(start_, end_, len(recv))
	if err != nil {
		return nil, fmt.Errorf("%s: %s", fnname, err)
	}

	var slice string
	if start < end {
		slice = recv[start:end]
	}
	return MakeInt(strings.Count(slice, sub)), nil
}
719868
func skip(value, prefix string) (string, error) {
	for len(prefix) > 0 {
		if prefix[0] == ' ' {
			if len(value) > 0 && value[0] != ' ' {
				return value, errBad
			}
			prefix = cutspace(prefix)
			value = cutspace(value)
			continue
		}
		if len(value) == 0 || value[0] != prefix[0] {
			return value, errBad
		}
		prefix = prefix[1:]
		value = value[1:]
	}
	return value, nil
}
478258
func (r *View) Skip(count int64) {
	for count > 0 {
		if r.cur == nil {
			panic(errors.New("cannot skip past end buffer"))
		}

		amount := r.chunkRemaining()
		if count < int64(amount) {
			amount = int(count)
			r.cidx += amount
		} else {
			// Finished consuming this chunk, move on to the next.
			r.cur = r.cur.next
			r.cidx = 0
		}

		count -= int64(amount)
		r.consumed += int64(amount)
		r.size -= int64(amount)
	}
}
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
}
272115
func (iter *Iterator) skipNumber() {
	for {
		for i := iter.head; i < iter.tail; i++ {
			c := iter.buf[i]
			switch c {
			case ' ', '\n', '\r', '\t', ',', '}', ']':
				iter.head = i
				return
			}
		}
		if !iter.loadMore() {
			return
		}
	}
}
179438
func (s Slice) ByteSize() (ValueLength, error) {
	h := s.head()
	// check if the type has a fixed length first
	l := fixedTypeLengths[h]
	if l != 0 {
		// return fixed length
		return ValueLength(l), nil
	}

	// types with dynamic lengths need special treatment:
	switch s.Type() {
	case Array, Object:
		if h == 0x13 || h == 0x14 {
			// compact Array or Object
			return readVariableValueLength(s, 1, false), nil
		}

		vpackAssert(h > 0x00 && h <= 0x0e)
		return ValueLength(readIntegerNonEmpty(s[1:], widthMap[h])), nil

	case String:
		vpackAssert(h == 0xbf)
		// long UTF-8 String
		return ValueLength(1 + 8 + readIntegerFixed(s[1:], 8)), nil

	case Binary:
		vpackAssert(h >= 0xc0 && h <= 0xc7)
		return ValueLength(1 + ValueLength(h) - 0xbf + ValueLength(readIntegerNonEmpty(s[1:], uint(h)-0xbf))), nil

	case BCD:
		if h <= 0xcf {
			// positive BCD
			vpackAssert(h >= 0xc8 && h < 0xcf)
			return ValueLength(1 + ValueLength(h) - 0xc7 + ValueLength(readIntegerNonEmpty(s[1:], uint(h)-0xc7))), nil
		}

		// negative BCD
		vpackAssert(h >= 0xd0 && h < 0xd7)
		return ValueLength(1 + ValueLength(h) - 0xcf + ValueLength(readIntegerNonEmpty(s[1:], uint(h)-0xcf))), nil

	case Custom:
		vpackAssert(h >= 0xf4)
		switch h {
		case 0xf4, 0xf5, 0xf6:
			return ValueLength(2 + readIntegerFixed(s[1:], 1)), nil
		case 0xf7, 0xf8, 0xf9:
			return ValueLength(3 + readIntegerFixed(s[1:], 2)), nil
		case 0xfa, 0xfb, 0xfc:
			return ValueLength(5 + readIntegerFixed(s[1:], 4)), nil
		case 0xfd, 0xfe, 0xff:
			return ValueLength(9 + readIntegerFixed(s[1:], 8)), nil
		}
	}

	return 0, WithStack(InternalError)
}
902942
func (e InconsistentEncodedSizeError) Error() string {
	return fmt.Sprintf("Block pointer to dirty block %v with non-zero "+
		"encoded size = %d bytes", e.info.ID, e.info.EncodedSize)
}