// parseTag splits the Repository tag from the prefix.
506571
func parseTag(s string) (prefix, tag string, err error) {
	splitString := strings.Split(s, ":")
	if len(splitString) == 1 {
		prefix = splitString[0]
	} else if len(splitString) == 2 {
		prefix, tag = splitString[0], splitString[1]
	} else {
		// Unlikely edge case but it doesn't hurt to test for it.
		return "", "", fmt.Errorf("Path should not contain more than one colon: %q", s)
	}

	if strings.HasSuffix(prefix, "/") {
		return "", "", fmt.Errorf(`Image name must not have a trailing "/": %s`, prefix)
	}

	return prefix, tag, nil
}
954109
func parseJSONTag(val string) (jsonTag, error) {
	if val == "-" {
		return jsonTag{ignore: true}, nil
	}

	var tag jsonTag

	i := strings.Index(val, ",")
	if i == -1 || val[:i] == "" {
		return tag, fmt.Errorf("malformed json tag: %s", val)
	}

	tag = jsonTag{
		apiName: val[:i],
	}

	switch val[i+1:] {
	case "omitempty":
	case "omitempty,string":
		tag.stringFormat = true
	default:
		return tag, fmt.Errorf("malformed json tag: %s", val)
	}

	return tag, nil
}
888057
func parseThing(thing *redditThing) (interface{}, error) {
	switch thing.Kind {
	case listingKind:
		return unmarshalListing(thing.Data)
	case commentKind:
		return unmarshalComment(thing.Data)
	case linkKind:
		return unmarshalLink(thing.Data)
	case messageKind:
		return unmarshalMessage(thing.Data)
	}
	return nil, fmt.Errorf("Unrecognized message kind")
}
1018449
func parseTagFields(file *os.File) ([]TagField, []error) {
	var errors []error
	re, err := regexp.Compile(`^(\S*\:)?(\s.*)?$`)
	if err != nil {
		errors = append(errors, err)
		return nil, errors
	}

	scanner := bufio.NewScanner(file)
	var fields []TagField
	var field TagField

	// Parse the remaining lines.
	for scanner.Scan() {
		line := scanner.Text()
		// See http://play.golang.org/p/zLqvg2qo1D for some testing on the field match.
		if re.MatchString(line) {
			data := re.FindStringSubmatch(line)
			data[1] = strings.Replace(data[1], ":", "", 1)
			if data[1] != "" {
				if field.Label() != "" {
					fields = append(fields, field)
				}
				field = *NewTagField(data[1], strings.Trim(data[2], " "))
				continue
			}
			value := strings.Trim(data[2], " ")
			field.SetValue(strings.Join([]string{field.Value(), value}, " "))

		} else {
			err := fmt.Errorf("Unable to parse tag data from line: %s", line)
			errors = append(errors, err)
		}
	}
	if field.Label() != "" {
		fields = append(fields, field)
	}

	if scanner.Err() != nil {
		errors = append(errors, scanner.Err())
	}

	// See http://play.golang.org/p/nsw9zsAEPF for some testing on the field match.
	return fields, errors
}
175102
func NewTag(code int, value DataType) *Tag {
	tag := new(Tag)
	tag.Code = code
	tag.Value = value
	return tag
}
758917
func parseFlag(flagStr string) (int, error) {
	flagStr = strings.TrimSpace(flagStr)
	if len(flagStr) == 0 {
		return 0, nil
	}

	strs := strings.Split(flagStr, "|")
	ret := 0

	for _, str := range strs {
		str = strings.ToLower(strings.TrimSpace(str))
		flag, found := flagMap[str]
		if !found {
			return 0, errors.New("无效的 flag:" + str)
		}
		ret |= flag
	}

	return ret, nil
}
1018440
func parseTagSetting(str string) map[string]string {
	tags := strings.Split(str, ";")
	setting := map[string]string{}
	for _, value := range tags {
		v := strings.Split(value, ":")
		k := strings.TrimSpace(strings.ToLower(v[0]))
		if len(v) >= 2 {
			setting[k] = strings.Join(v[1:], ":")
		} else {
			setting[k] = k
		}
	}
	return setting
}
563749
func sliceBundleTag(data []byte) ([]byte, error) {
	bundleTag := append([]byte(BundleTag), 0)
	if len(data) < len(bundleTag) {
		return nil, errors.Errorf("expected %q, got %q", bundleTag, data)
	}
	idx := bytes.Index(data, bundleTag)
	if idx == -1 {
		return nil, errors.Errorf("expected %q, got %q", bundleTag, data[:len(bundleTag)])
	}
	return data[len(bundleTag):], nil
}
1038079
func AnnotationFromLexTag(l Lexeme, t POSTag, f AnnotationFixer) *Annotation {
	a := &Annotation{
		Lexeme:         l,
		POSTag:         t,
		DependencyType: NoDepType,
		Lemma:          "",
		Lowered:        strings.ToLower(l.Value),
	}

	// it's ok to panic - it will cause the tests to fail
	if err := a.Process(f); err != nil {
		panic(err)
	}

	return a
}
749280
func (w *xmlWriter) CloseTag(tag []string) error {
	return w.context.Writef("</%s>", tag[0])
}
511858
func NewTag(key, value []byte) Tag {
	return Tag{
		Key:   key,
		Value: value,
	}
}
615346
func parseTagFlag(tagFlag string) (tag string, err error) {
	tags := strings.Fields(tagFlag)
	if len(tags) != 1 {
		return "", fmt.Errorf("%q is not a valid single build tag, but %q", tagFlag, tags)
	}
	return tags[0], nil
}
1262463
func parseMountFlag(m string) (specs.Mount, error) {
	mount := specs.Mount{}
	r := csv.NewReader(strings.NewReader(m))

	fields, err := r.Read()
	if err != nil {
		return mount, err
	}

	for _, field := range fields {
		v := strings.Split(field, "=")
		if len(v) != 2 {
			return mount, fmt.Errorf("invalid mount specification: expected key=val")
		}

		key := v[0]
		val := v[1]
		switch key {
		case "type":
			mount.Type = val
		case "source", "src":
			mount.Source = val
		case "destination", "dst":
			mount.Destination = val
		case "options":
			mount.Options = strings.Split(val, ":")
		default:
			return mount, fmt.Errorf("mount option %q not supported", key)
		}
	}

	return mount, nil
}
1022169
func (d *Decoder) UseJSONTag(v bool) *Decoder {
	d.useJSONTag = v
	return d
}
984505
func ParseTags(m string) Tags {
	maxNum := 5
	tags := make(Tags)
	var r rune
	var i_s int = 0

	for i := 0; i < len(m); i += i_s {
		r, i_s = utf8.DecodeRuneInString(m[i:])
		if r == '#' {
			var j_s int
			var v rune
			var j int
			for j = i; j < len(m); j += j_s {
				v, j_s = utf8.DecodeRuneInString(m[j:])
				if isTagBreak(v) {
					break
				}
			}
			tag := Tag(m[i:j])
			//fmt.Printf("i: %d, j: %d, tag: %s\n", i, j, tag)
			if len(tags) >= maxNum {
				break
			}
			tags[tag] = struct{}{}
			i = j
			i_s = 0
		}
	}
	return tags
}
135428
func GetTag(image string) string {
	if !strings.Contains(image, ":") {
		return DefaultVersion
	}

	parts := strings.Split(image, ":")
	if len(parts) != 2 {
		return WrongVersion
	}

	return parts[len(parts)-1]
}
1255179
func ParseTagSliceToMap(tags []string) map[string]string {
	mappedTags := make(map[string]string)
	for _, tag := range tags {
		splt := strings.SplitN(tag, ":", 2)
		if len(splt) < 2 {
			mappedTags[splt[0]] = ""
		} else {
			mappedTags[splt[0]] = splt[1]
		}
	}
	return mappedTags
}