// splitToSubN splits a string every n runes into a string[]
353585
func splitToSubN(s string, n int) []string {
	subs := make([]string, 0, len(s)/n+1)
	for len(s) > n {
		subs = append(subs, s[:n])
		s = s[n:]
	}
	subs = append(subs, s)
	return subs
}
1023938
func (s Subscription) Split() (p, n string) {
	p, n, _ = s.SplitErr()
	return
}
900265
func SplitFilter(s, sep string, f func(p string) bool) []string {
	parts := strings.Split(s, sep)
	out := []string{}
	for _, part := range parts {
		if f(part) {
			out = append(out, part)
		}
	}
	return out
}
499599
func (n *node) splitTwo(pageSize int) (*node, *node) {
	// Ignore the split if the page doesn't have at least enough nodes for
	// two pages or if the nodes can fit in a single page.
	if len(n.inodes) <= (minKeysPerPage*2) || n.sizeLessThan(pageSize) {
		return n, nil
	}

	// Determine the threshold before starting a new node.
	var fillPercent = n.bucket.FillPercent
	if fillPercent < minFillPercent {
		fillPercent = minFillPercent
	} else if fillPercent > maxFillPercent {
		fillPercent = maxFillPercent
	}
	threshold := int(float64(pageSize) * fillPercent)

	// Determine split position and sizes of the two pages.
	splitIndex, _ := n.splitIndex(threshold)

	// Split node into two separate nodes.
	// If there's no parent then we'll need to create one.
	if n.parent == nil {
		n.parent = &node{bucket: n.bucket, children: []*node{n}}
	}

	// Create a new node and add it to the parent.
	next := &node{bucket: n.bucket, isLeaf: n.isLeaf, parent: n.parent}
	n.parent.children = append(n.parent.children, next)

	// Split inodes across two nodes.
	next.inodes = n.inodes[splitIndex:]
	n.inodes = n.inodes[:splitIndex]

	// Update the statistics.
	n.bucket.tx.stats.Split++

	return n, next
}
459919
func splitRange(start, stop, n int, fn func(pstart, pstop int)) {
	count := stop - start
	if count < 1 {
		return
	}

	if n < 1 {
		n = 1
	}
	if n > count {
		n = count
	}

	div := count / n
	mod := count % n

	for i := 0; i < n; i++ {
		fn(
			start+i*div+minint(i, mod),
			start+(i+1)*div+minint(i+1, mod),
		)
	}
}
558346
func SplitString(b []byte) (content, rest []byte, err error) {
	k, content, rest, err := Split(b)
	if err != nil {
		return nil, b, err
	}
	if k == List {
		return nil, b, ErrExpectedString
	}
	return content, rest, nil
}
948316
func splitTags(tags string) (string, options) {
	res := strings.Split(tags, ",")
	return res[0], res[1:]
}
724697
func SplitString(str string) []string {
	if len(str) == 0 {
		return []string{}
	}

	return regexp.MustCompile("[, ]+").Split(str, -1)
}
1240421
func split255(s string) []string {
	if len(s) < 255 {
		return []string{s}
	}
	sx := []string{}
	p, i := 0, 255
	for {
		if i <= len(s) {
			sx = append(sx, s[p:i])
		} else {
			sx = append(sx, s[p:])
			break

		}
		p, i = p+255, i+255
	}

	return sx
}
275052
func split(s string) ([]string, bool) {
	if s == "" {
		return nil, false
	}
	ret := make([]string, 0)
	ccase := 0
	const UPPER_CASE = 1
	const LOWER_CASE = 2
	word := bytes.NewBufferString("")
	for i := 0; i < len(s); i++ {
		b := s[i]
		if b >= 'A' && b <= 'Z' {
			if ccase != UPPER_CASE {
				if word.Len() > 0 {
					ret = append(ret, word.String())
					word.Reset()
				}
			}
			word.WriteByte(b)
			ccase = UPPER_CASE
		} else if b >= 'a' && b <= 'z' {
			word.WriteByte(b)
			ccase = LOWER_CASE
		} else if b == '_' {
			if word.Len() > 0 {
				ret = append(ret, word.String())
			}
			ccase = 0
			word.Reset()
		} else if b >= '0' && b <= '9' {
			word.WriteByte(b)
		} else {
			return nil, false
		}
		if i+1 == len(s) && word.Len() > 0 {
			ret = append(ret, word.String())
		}
	}
	return ret, true
}
41931
func splitName(name string) (string, string) {
	parts := strings.SplitN(name, ".", 2)
	if len(parts) > 1 {
		return parts[0], parts[1]
	}
	return "", parts[0]
}
797092
func LastNLines(s string, n int) string {
	trimmed := strings.Trim(s, "\n")
	splitted := strings.Split(trimmed, "\n")

	if len(splitted) >= n {
		splitted = splitted[len(splitted)-n:]
	}

	return strings.Join(splitted, "\n")
}
1246574
func split(s string, c string, cutc bool) (string, string) {
	i := strings.Index(s, c)
	if i < 0 {
		return s, ""
	}
	if cutc {
		return s[:i], s[i+len(c):]
	}
	return s[:i], s[i:]
}
450863
func splitPathOnSeparator(path string, separator rune) []string {
	// if the separator is '\\', then we can just split...
	if separator == '\\' {
		return strings.Split(path, string(separator))
	}

	// otherwise, we need to be careful of situations where the separator was escaped
	cnt := strings.Count(path, string(separator))
	if cnt == 0 {
		return []string{path}
	}
	ret := make([]string, cnt+1)
	pathlen := len(path)
	separatorLen := utf8.RuneLen(separator)
	idx := 0
	for start := 0; start < pathlen; {
		end := indexRuneWithEscaping(path[start:], separator)
		if end == -1 {
			end = pathlen
		} else {
			end += start
		}
		ret[idx] = path[start:end]
		start = end + separatorLen
		idx++
	}
	return ret[:idx]
}
594756
func (hpt *hostParamTransformer) split(s, sep string) []string {
	slice := []string{}
	n := strings.Count(s, sep) + 1
	c := sep[0]
	start := 0

	var a []string
	if cap(slice) == n {
		a = slice
	} else {
		a = make([]string, n)
	}

	na := 0
	for i := 0; i+len(sep) <= len(s) && na+1 < n; i++ {
		if s[i] == c && (len(sep) == 1 || s[i:i+len(sep)] == sep) && (i == 0 || s[i-1] != '\\') {
			a[na] = s[start:i]
			na++
			start = i + len(sep)
			i += len(sep) - 1
		}
	}
	a[na] = s[start:]
	slice = a[0 : na+1]
	return slice
}
185915
func (ns *Namespace) Split(a interface{}, delimiter string) ([]string, error) {
	aStr, err := cast.ToStringE(a)
	if err != nil {
		return []string{}, err
	}

	return _strings.Split(aStr, delimiter), nil
}
309751
func (wr *Wrangler) SplitClone(ctx context.Context, keyspace string, from, to []string) error {
	var fromShards, toShards []*topo.ShardInfo
	for _, shard := range from {
		si, err := wr.ts.GetShard(ctx, keyspace, shard)
		if err != nil {
			return vterrors.Wrapf(err, "GetShard(%s) failed", shard)
		}
		fromShards = append(fromShards, si)
	}
	for _, shard := range to {
		si, err := wr.ts.GetShard(ctx, keyspace, shard)
		if err != nil {
			return vterrors.Wrapf(err, "GetShard(%s) failed", shard)
		}
		toShards = append(toShards, si)
	}
	// TODO(sougou): validate from and to shards.

	for _, dest := range toShards {
		master, err := wr.ts.GetTablet(ctx, dest.MasterAlias)
		if err != nil {
			return vterrors.Wrapf(err, "GetTablet(%v) failed", dest.MasterAlias)
		}
		var ids []uint64
		for _, source := range fromShards {
			filter := &binlogdatapb.Filter{
				Rules: []*binlogdatapb.Rule{{
					Match:  "/.*",
					Filter: key.KeyRangeString(dest.KeyRange),
				}},
			}
			bls := &binlogdatapb.BinlogSource{
				Keyspace: keyspace,
				Shard:    source.ShardName(),
				Filter:   filter,
			}
			cmd := binlogplayer.CreateVReplicationState("VSplitClone", bls, "", binlogplayer.BlpStopped, master.DbName())
			qr, err := wr.TabletManagerClient().VReplicationExec(ctx, master.Tablet, cmd)
			if err != nil {
				return vterrors.Wrapf(err, "VReplicationExec(%v, %s) failed", dest.MasterAlias, cmd)
			}
			if err := wr.SourceShardAdd(ctx, keyspace, dest.ShardName(), uint32(qr.InsertId), keyspace, source.ShardName(), source.Shard.KeyRange, nil); err != nil {
				return vterrors.Wrapf(err, "SourceShardAdd(%s, %s) failed", dest.ShardName(), source.ShardName())
			}
			ids = append(ids, qr.InsertId)
		}
		// Start vreplication only if all metadata was successfully created.
		for _, id := range ids {
			cmd := fmt.Sprintf("update _vt.vreplication set state='%s' where id=%d", binlogplayer.VReplicationInit, id)
			if _, err = wr.TabletManagerClient().VReplicationExec(ctx, master.Tablet, cmd); err != nil {
				return vterrors.Wrapf(err, "VReplicationExec(%v, %s) failed", dest.MasterAlias, cmd)
			}
		}
	}
	return wr.refreshMasters(ctx, toShards)
}