// splitAfterNewline splits p after "\n", the split is assigned to lines
// if last line has no "\n" it is assigned to the chunk.
// If p is nil both lines and chunk is set to nil.
978063
func splitAfterNewline(p []byte) ([][]byte, []byte) {
	chunk := p
	var lines [][]byte

	for len(chunk) > 0 {
		idx := bytes.Index(chunk, newLine)
		if idx == -1 {
			return lines, chunk
		}

		lines = append(lines, chunk[:idx+1])

		if idx == len(chunk)-1 {
			chunk = nil
			break
		}

		chunk = chunk[idx+1:]
	}

	return lines, chunk
}
961613
func (cs Set) Split() (domain, target, ref string) {
	switch p := strings.SplitN(string(cs), "/", 3); len(p) {
	case 1:
		return p[0], "", ""
	case 2:
		return p[0], p[1], ""
	default:
		return p[0], p[1], p[2]
	}
}
1169264
func SplitExtension(name string) (
	assertions, extensionSuffix string, err error) {
	names := strings.SplitN(name, HandleExtensionSep, 2)
	if len(names) > 2 {
		return "", "", BadNameError{name}
	}
	if len(names) > 1 {
		extensionSuffix = names[1]
	}
	return names[0], extensionSuffix, nil
}
450947
func CheckHandleOffline(
	ctx context.Context, name string, t tlf.Type) error {
	_, _, _, err := idutil.SplitAndNormalizeTLFName(name, t)
	return err
}
1188988
func splitCombine(inStrs []string) []string {
	outStrs := make([]string, 0)
	for _, str := range inStrs {
		inStrs := strings.Fields(str)
		outStrs = append(outStrs, inStrs...)
	}
	return outStrs
}
64752
func (p *responseParser) errorFromLine(line []byte) (error, bool) {
	split := strings.SplitN(string(line), " ", 2)
	if len(split[0]) <= 1 {
		return ErrMalformed, false
	}

	code := split[0][1:]
	var text string
	if len(split) == 2 {
		if len(split[1]) == 0 {
			return ErrMalformed, false
		}

		text = split[1]
	}

	return NewResponseError(code, text), true
}
190001
func Split(delim, escape rune, v string) []string {
	if delim == 0 || escape == 0 {
		return []string{v}
	}
	scanner := bufio.NewScanner(strings.NewReader(v))
	s := &splitter{delim: delim, escape: escape}
	scanner.Split(s.scan)

	out := []string{}
	for scanner.Scan() {
		out = append(out, scanner.Text())
	}
	return out
}
937856
func LinesBeforeAndAfter(data []byte, line, before, after int, lineNumbers bool) []byte {
	// TODO(gemnasium): Trim empty lines at the beginning and at the end
	// TODO(gemnasium): Trim offset whitespace at the beginning of each line, so that indentation is preserved
	startLine := line - before
	endLine := line + after
	lines := bytes.SplitN(data, []byte("\n"), endLine+1)

	if startLine < 0 {
		startLine = 0
	}
	if endLine > len(lines) {
		endLine = len(lines)
	}

	selectLines := lines[startLine:endLine]
	newLines := make([][]byte, 0)
	lineCounter := startLine + 1
	lineNumberDigits := len(strconv.Itoa(len(selectLines)))
	for _, l := range selectLines {
		lineCounterStr := strconv.Itoa(lineCounter)
		if len(lineCounterStr)%lineNumberDigits != 0 {
			lineCounterStr = strings.Repeat(" ", lineNumberDigits-len(lineCounterStr)%lineNumberDigits) + lineCounterStr
		}

		lNew := l
		if lineNumbers {
			lNew = append([]byte(lineCounterStr+": "), lNew...)
		}
		newLines = append(newLines, lNew)
		lineCounter += 1
	}

	return bytes.Join(newLines, []byte("\n"))
}
1012304
func splitAndTrim(s string) (result []string) {
	last := 0
	var lastChar byte
	excludeFromSplit := []byte{'>', '<', '='}
	for i := 0; i < len(s); i++ {
		if s[i] == ' ' && !inArray(lastChar, excludeFromSplit) {
			if last < i-1 {
				result = append(result, s[last:i])
			}
			last = i + 1
		} else if s[i] != ' ' {
			lastChar = s[i]
		}
	}
	if last < len(s)-1 {
		result = append(result, s[last:])
	}

	for i, v := range result {
		result[i] = strings.Replace(v, " ", "", -1)
	}

	// parts := strings.Split(s, " ")
	// for _, x := range parts {
	// 	if s := strings.TrimSpace(x); len(s) != 0 {
	// 		result = append(result, s)
	// 	}
	// }
	return
}
1297611
func (splitter *Splitter) Split() ([]*querypb.QuerySplit, error) {
	var boundaries []tuple
	var err error
	boundaries, err = splitter.algorithm.generateBoundaries()
	if err != nil {
		return nil, err
	}
	boundaries = append(boundaries, nil)
	splits := []*querypb.QuerySplit{}
	var start tuple
	for _, end := range boundaries {
		splits = append(splits, splitter.constructQueryPart(start, end))
		start = end
	}
	return splits, nil
}
149687
func splitInclude(s string) (string, string) {
	if i := strings.IndexRune(s, '.'); i > 0 {
		return s[:i], s[i+1:]
	}
	return "", s
}
51908
func (f File) Split(sep string) []string {
	pat := fmt.Sprintf("\r?\n{0,1}%s\r?\n{0,1}", regexp.QuoteMeta(sep))
	re := regexp.MustCompile(pat)
	return re.Split(f.String(), -1)
}
820947
func SplitFileLines(f *os.File, numParts int64) ([]*FileFragment, error) {
	stats, err := f.Stat()
	if err != nil {
		return nil, err
	}
	splitSize := stats.Size() / numParts

	ret := make([]*FileFragment, 0)
	var startLoc int64
	for {
		endLoc, errSeek := seekAndSearch(f, splitSize, '\n')
		if errSeek != nil && errSeek != io.EOF {
			return nil, errors.Wrap(errSeek, "searching for next split location")
		}
		ff, err := NewFileFragment(f, startLoc, endLoc)
		if err != nil {
			return nil, errors.Wrap(err, "creating new file fragment")
		}
		ret = append(ret, ff)
		if errSeek == io.EOF {
			break
		}
		startLoc = endLoc
	}
	return ret, nil
}
496194
func (s *scalarRange) split() (scalarRange, scalarRange) {
	if s.start < 0xe000 && s.end > 0xd7ff {
		return scalarRange{
				start: s.start,
				end:   0xd7ff,
			},
			scalarRange{
				start: 0xe000,
				end:   s.end,
			}
	}
	return nilScalarRange, nilScalarRange
}
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:]
}
327109
func SplitPath(path string) []string {
	p := strings.TrimPrefix(path, "/")
	return strings.Split(strings.TrimSuffix(p, "/"), "/")
}
178159
func SplitProtoPort(rawPort string) (string, string) {
	parts := strings.Split(rawPort, "/")
	l := len(parts)
	if len(rawPort) == 0 || l == 0 || len(parts[0]) == 0 {
		return "", ""
	}
	if l == 1 {
		return "tcp", rawPort
	}
	if len(parts[1]) == 0 {
		return "tcp", parts[0]
	}
	return parts[1], parts[0]
}