// SplitProtoPort splits a port in the format of proto/port
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]
}
193483
func SplitMrt(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if cap(data) < MRT_COMMON_HEADER_LEN { // read more
		return 0, nil, nil
	}
	//this reads the data
	hdr := &MRTHeader{}
	errh := hdr.DecodeFromBytes(data[:MRT_COMMON_HEADER_LEN])
	if errh != nil {
		return 0, nil, errh
	}
	totlen := int(hdr.Len + MRT_COMMON_HEADER_LEN)
	if len(data) < totlen { //need to read more
		return 0, nil, nil
	}
	return totlen, data[0:totlen], nil
}
1268016
func splitPrefixes(prefixes ...[]byte) ([]byte, [][]byte) {
	switch {
	case len(prefixes) == 0 || len(prefixes[0]) == 0:
		return nil, prefixes
	case len(prefixes) == 1:
		return prefixes[0], nil
	}

	var prefix []byte
	for i := 0; ; i++ {
		var cur byte
		var matched bool
		for j, prefix := range prefixes {
			switch {
			case len(prefix) <= i:
				matched = true
				break

			case j == 0:
				cur = prefix[i]
				continue

			case cur != prefix[i]:
				matched = true
				break
			}
		}

		if matched {
			break
		}

		prefix = append(prefix, cur)
	}

	next := make([][]byte, 0, len(prefixes))
	for _, remaining := range prefixes {
		next = append(next, remaining[len(prefix):])
	}
	return prefix, next
}
182346
func (itc *internalTabletConn) SplitQuery(
	ctx context.Context,
	target *querypb.Target,
	query *querypb.BoundQuery,
	splitColumns []string,
	splitCount int64,
	numRowsPerQueryPart int64,
	algorithm querypb.SplitQueryRequest_Algorithm) ([]*querypb.QuerySplit, error) {

	splits, err := itc.tablet.qsc.QueryService().SplitQuery(
		ctx,
		target,
		query,
		splitColumns,
		splitCount,
		numRowsPerQueryPart,
		algorithm)
	if err != nil {
		return nil, tabletconn.ErrorFromGRPC(vterrors.ToGRPC(err))
	}
	return splits, nil
}
762669
func (p Port) Proto() string {
	parts := strings.Split(string(p), "/")
	if len(parts) == 1 {
		return "tcp"
	}
	return parts[1]
}
466866
func (p Port) Port() string {
	_, port := SplitProtoPort(string(p))
	return port
}
683827
func mustSplitHostPort(hostPort string) (host, port string) {
	host, port, err := net.SplitHostPort(hostPort)
	// Strip off IPv6 zone information.
	if i := strings.Index(host, "%"); i > -1 {
		host = host[:i]
	}
	logger.FatalIf(err, "Unable to split host port %s", hostPort)
	return host, port
}
197400
func splitHostnamePartsFromHost(fullHost string, defaultPortNum string) (string, string) {

	h := strings.Split(fullHost, ":")

	if len(h) == 2 {
		return h[0], h[1]
	}

	return h[0], defaultPortNum
}
429211
func SrcPort(port uint16) TransportChecker {
	return func(t *testing.T, h header.Transport) {
		t.Helper()

		if p := h.SourcePort(); p != port {
			t.Errorf("Bad source port, got %v, want %v", p, port)
		}
	}
}
1271751
func portMappingToHostport(portMapping *PortMapping) hostport {
	return hostport{
		port:     portMapping.HostPort,
		protocol: strings.ToLower(string(portMapping.Protocol)),
	}
}
529742
func SplitHostPort(pair string) (string, string, error) {
	if host, port, err := net.SplitHostPort(pair); err == nil {
		return host, port, nil
	}

	h := strings.SplitN(pair, ":", 2)
	if len(h) != 2 {
		return "", "", fmt.Errorf("unable to parse proto from %q", pair)
	}
	return h[0], h[1], nil
}
453221
func splitExtension(path string) (string, string) {
	for i := len(path) - 1; i > 0; i-- {
		switch path[i] {
		case '.':
			// Handle some multipart extensions
			if i >= 4 && path[i-4:i] == ".tar" {
				i -= 4
			}
			// A leading dot is not an extension
			if i == 0 || path[i-1] == '/' || path[i-1] == '\\' {
				return path, ""
			}
			return path[:i], path[i:]
		case '/', '\\', ' ':
			return path, ""
		}
	}
	return path, ""
}
512423
func convertProtoMount(in *proto.Mount) *Mount {
	if in == nil {
		return nil
	}

	return &Mount{
		TaskPath: in.TaskPath,
		HostPath: in.HostPath,
		ReadOnly: in.ReadOnly,
	}
}
1313108
func ParseHostPort(hostport string) (string, string, error) {
	var host, port string
	var err error

	// try to split host and port
	if host, port, err = net.SplitHostPort(hostport); err != nil {
		// if SplitHostPort returns an error, the entire hostport is considered as host
		host = hostport
	}

	// if port is defined, parse and validate it
	if port != "" {
		if _, err := ParsePort(port); err != nil {
			return "", "", errors.Errorf("hostport %s: port %s must be a valid number between 1 and 65535, inclusive", hostport, port)
		}
	}

	// if host is a valid IP, returns it
	if ip := net.ParseIP(host); ip != nil {
		return host, port, nil
	}

	// if host is a validate RFC-1123 subdomain, returns it
	if errs := validation.IsDNS1123Subdomain(host); len(errs) == 0 {
		return host, port, nil
	}

	return "", "", errors.Errorf("hostport %s: host '%s' must be a valid IP address or a valid RFC-1123 DNS subdomain", hostport, host)
}
372561
func splitAddr(addr string) (string, string, string, error) {
	scheme, hostPort := splitScheme(addr)
	host, port := "", ""
	if hostPort != "" {
		var err error
		host, port, err = net.SplitHostPort(hostPort)
		if err != nil {
			return "", "", "", errors.Wrapf(err, "splitting host port: %s", hostPort)
		}
	}
	// It's not ideal to have a default here, but the alterative
	// results in a port of 0, which causes Pilosa to listen on
	// a random port.
	if port == "" {
		port = "10101"
	}
	return scheme, host, port, nil
}
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
}
150653
func (s *Stack) TransportProtocolInstance(num tcpip.TransportProtocolNumber) TransportProtocol {
	if pState, ok := s.transportProtocols[num]; ok {
		return pState.proto
	}
	return nil
}