// ParseDedupAndSortStrings parses a comma separated list of strings
// into a slice of strings. The return slice will be sorted and will
// not contain duplicate or empty items.
349932
func ParseDedupAndSortStrings(input string, sep string) []string {
	input = strings.TrimSpace(input)
	parsed := []string{}
	if input == "" {
		// Don't return nil
		return parsed
	}
	return RemoveDuplicates(strings.Split(input, sep), false)
}
199927
func uniqueStrings(s []string) []string {
	if len(s) < 2 {
		return s
	}

	sort.Strings(s)
	result := make([]string, 1, len(s))
	result[0] = s[0]
	for i := 1; i < len(s); i++ {
		if s[i] != result[len(result)-1] {
			result = append(result, s[i])
		}
	}
	return result
}
952914
func sortedQueryString(values url.Values) string {
	if len(values) == 0 {
		return ""
	}
	pairs := make(sortedPairs, 0)
	for k, vs := range values {
		escK := Rfc3986Escape(k)
		for _, v := range vs {
			pairs = append(pairs, pair{escK, Rfc3986Escape(v)})
		}
	}
	sort.Sort(pairs)

	buf := new(bytes.Buffer)
	buf.WriteString(pairs[0].k)
	buf.WriteByte('=')
	buf.WriteString(pairs[0].v)

	for _, p := range pairs[1:] {
		buf.WriteByte('&')
		buf.WriteString(p.k)
		buf.WriteByte('=')
		buf.WriteString(p.v)
	}
	return buf.String()
}
112780
func ParseServices(ports []string) ([]common.Service, error) {

	// If no ports are provided, we add the default 0 port
	if len(ports) == 0 {
		ports = append(ports, "0")
	}

	// Parse the ports and create the services. Cleanup any bad ports
	services := []common.Service{}
	protocol := packet.IPProtocolTCP

	for _, p := range ports {
		// check for port string of form port#/udp eg 8085/udp
		portProtocolPair := strings.Split(p, "/")
		if len(portProtocolPair) > 2 || len(portProtocolPair) <= 0 {
			return nil, fmt.Errorf("Invalid port format. Expected format is of form 80 or 8085/udp")
		}

		if len(portProtocolPair) == 2 {
			if portProtocolPair[1] == "tcp" {
				protocol = packet.IPProtocolTCP
			} else if portProtocolPair[1] == "udp" {
				protocol = packet.IPProtocolUDP
			} else {
				return nil, fmt.Errorf("Invalid protocol specified. Only tcp/udp accepted")
			}
		}

		s, err := portspec.NewPortSpecFromString(portProtocolPair[0], nil)
		if err != nil {
			return nil, fmt.Errorf("Invalid port spec: %s ", err)
		}

		services = append(services, common.Service{
			Protocol: uint8(protocol),
			Ports:    s,
		})
	}

	return services, nil
}
298297
func JoinStringSlices(a []string, b []string) []string {
	if len(a)+len(b) == 0 {
		return nil
	}
	out := make([]string, 0, len(a)+len(b))
	out = append(out, a...)
	out = append(out, b...)
	return out
}
815369
func ParseArgs(args []string) (string, []string, bool) {

	if len(args) == 0 {
		return "", []string{}, false
	}

	pluginName := ""
	pluginArgs := []string{}
	for idx, arg := range args {

		if strings.Contains(arg, bitrisePluginPrefix) {
			pluginSplits := strings.Split(arg, ":")

			if len(pluginSplits) != 2 {
				return "", []string{}, false
			}

			pluginName = pluginSplits[1]
			if len(args) > idx {
				pluginArgs = args[idx+1 : len(args)]
			}
			return pluginName, pluginArgs, true
		}
	}

	return "", []string{}, false
}
592486
func (p *Parser) parseSortField() (*SortField, error) {
	field := &SortField{}

	// Parse sort field name.
	ident, err := p.ParseIdent()
	if err != nil {
		return nil, err
	}
	field.Name = ident

	// Check for optional ASC or DESC clause. Default is ASC.
	tok, _, _ := p.ScanIgnoreWhitespace()
	if tok != ASC && tok != DESC {
		p.Unscan()
		tok = ASC
	}
	field.Ascending = (tok == ASC)

	return field, nil
}
177313
func (cmd *CLI) parseFlags(args []string) []string {
	cmd.defineHelp()
	cmd.defineVersion()
	cmd.initFlagValues()

	// Set all the flags to defaults before setting
	cmd.setFlagDefaults()

	// copy propogating flags
	cmd.copyPropogatingFlags()

	// Set inherited values
	cmd.setFlagValuesFromParent()

	var paramIndex int
	var nonFlags []string

	// Set each flag by its set value
	for {
		// Break if no arguments remain
		if len(args) == 0 {
			cmd.flagsTerminated = true
			break
		}
		arg := args[0]

		if arg[0] != '-' { // Parse Param

			if paramIndex == len(cmd.params) && len(cmd.subCommands) > 0 {
				break
			}
			nonFlags = append(nonFlags, arg)
			paramIndex++
			args = args[1:]

		} else { // Parse Flags

			isAlias, flags := cmd.flagFromArg(arg)

			// Break if the flags have been terminated
			if cmd.flagsTerminated {
				// Remove the flag terminator if it exists
				if arg == "--" {
					args = args[1:]
				}
				break
			}

			// Set flag values
			if isAlias {
				args = cmd.setAliasValues(flags, args)
			} else {
				args = cmd.setFlagValue(flags[0], args)
			}
		}
	}

	// reposition the Args so that they may still be parsed
	args = append(nonFlags, args...)

	// return the remaining unused args
	return args
}
76810
func chunkStrings(s []*string, size int) [][]*string {
	var chunks [][]*string
	for len(s) > 0 {
		end := size
		if len(s) < size {
			end = len(s)
		}

		chunks = append(chunks, s[0:end])
		s = s[end:]
	}
	return chunks
}
1233950
func (v *OrderedValues) StringAdd(key, val string) {
	if len(key) == 0 {
		return
	}
	if len(val) == 0 {
		v.Add([]byte(key), chrs[0:0])
	} else {
		v.Add([]byte(key), []byte(val))
	}
}
509362
func (t TagMap) SortedKeys() []string {
	if len(t) == 0 {
		return nil
	}

	keys := make([]string, 0, len(t))
	for k := range t {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	return keys
}
509754
func ParseSupportedVersions(s string) (SupportedVersions, error) {
	var err error
	list := strings.Split(s, ",")
	versions := make(SupportedVersions, len(list))
	for i, v := range list {
		versions[i], err = ParseEtcdVersion(strings.TrimSpace(v))
		if err != nil {
			return nil, err
		}
	}
	return versions, nil
}
812637
func ParseDestination(targetString string, defaultTabletType topodatapb.TabletType) (string, topodatapb.TabletType, key.Destination, error) {
	var dest key.Destination
	var keyspace string
	tabletType := defaultTabletType

	last := strings.LastIndexAny(targetString, "@")
	if last != -1 {
		// No need to check the error. UNKNOWN will be returned on
		// error and it will fail downstream.
		tabletType, _ = ParseTabletType(targetString[last+1:])
		targetString = targetString[:last]
	}
	last = strings.LastIndexAny(targetString, "/:")
	if last != -1 {
		dest = key.DestinationShard(targetString[last+1:])
		targetString = targetString[:last]
	}
	// Try to parse it as a keyspace id or range
	last = strings.LastIndexAny(targetString, "[")
	if last != -1 {
		rangeEnd := strings.LastIndexAny(targetString, "]")
		if rangeEnd == -1 {
			return keyspace, tabletType, dest, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid key range provided. Couldn't find range end ']'")
		}
		rangeString := targetString[last+1 : rangeEnd]
		if strings.Contains(rangeString, "-") {
			// Parse as range
			keyRange, err := key.ParseShardingSpec(rangeString)
			if err != nil {
				return keyspace, tabletType, dest, err
			}
			if len(keyRange) != 1 {
				return keyspace, tabletType, dest, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "single keyrange expected in %s", rangeString)
			}
			dest = key.DestinationExactKeyRange{KeyRange: keyRange[0]}
		} else {
			// Parse as keyspace id
			destBytes, err := hex.DecodeString(rangeString)
			if err != nil {
				return keyspace, tabletType, dest, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "expected valid hex in keyspace id %s", rangeString)
			}
			dest = key.DestinationKeyspaceID(destBytes)
		}
		targetString = targetString[:last]
	}
	keyspace = targetString
	return keyspace, tabletType, dest, nil
}
844879
func (c *JSONConfigContainer) DefaultStrings(key string, defaultval []string) []string {
	if v := c.Strings(key); v != nil {
		return v
	}
	return defaultval
}
156747
func GetSupportedShells() []string {
	shells := []string{}
	for s := range completionShells {
		shells = append(shells, s)
	}
	return shells
}
424460
func (d *DecisionTreeNode) getNestedString(level int) string {
	buf := bytes.NewBuffer(nil)
	tmp := bytes.NewBuffer(nil)
	for i := 0; i < level; i++ {
		tmp.WriteString("\t")
	}
	buf.WriteString(tmp.String())
	if d.Children == nil {
		buf.WriteString(fmt.Sprintf("Leaf(%s)", d.Class))
	} else {
		var keys []string
		buf.WriteString(fmt.Sprintf("Rule(%s)", d.SplitRule))
		for k := range d.Children {
			keys = append(keys, k)
		}
		sort.Strings(keys)
		for _, k := range keys {
			buf.WriteString("\n")
			buf.WriteString(tmp.String())
			buf.WriteString("\t")
			buf.WriteString(k)
			buf.WriteString("\n")
			buf.WriteString(d.Children[k].getNestedString(level + 1))
		}
	}
	return buf.String()
}
199723
func sortedConcatStringMap(m map[string]*string) string {
	var strList []string
	mapKeys := sortStringMapKeys(m)
	for _, key := range mapKeys {
		strList = append(strList, key, *m[key])
	}
	return strings.Join(strList, "-")
}