// Parse parses input as template input using the addresses available on the
// host, then returns the string output if there are no errors.
357559
func Parse(input string) (string, error) {
	addrs, err := sockaddr.GetAllInterfaces()
	if err != nil {
		return "", errwrap.Wrapf("unable to query interface addresses: {{err}}", err)
	}

	return ParseIfAddrs(input, addrs)
}
603990
func (p IntParser) Parse(field string) (result interface{}, err error) {
	return strconv.ParseInt(field, 10, 64)
}
803913
func Parse(data string) (HashSet, string) {
	items := strings.Split(data, LineSeparator)
	hashItems := make(HashSet, 0, len(items))
	source := ""
	for _, e := range items {
		if strings.HasPrefix(e, SourceMarker) {
			source = strings.TrimPrefix(e, SourceMarker)
			log.Info("found source in patch:", source)
		}
		tokens := strings.Split(strings.TrimSpace(e), HashSplit)
		// ignore invalid entry
		if len(tokens) < 2 {
			continue
		}
		hashItems = append(hashItems, HashItem{tokens[0], tokens[1]})
	}
	log.Info("parsed", len(hashItems), "hash items")
	return hashItems, source
}
1250416
func Parse(s string) (*dt.Address, error) {
	s = regexAddress.FindString(s)
	if len(s) == 0 {
		log.Debug("missing address")
		return nil, ErrInvalidAddress
	}
	log.Debug("address", s)
	tmp := regexZip.FindStringIndex(s)
	var zip string
	if tmp != nil {
		zip = s[tmp[0]:tmp[1]]
		s = s[:tmp[0]]
	} else {
		log.Debug("no zip found")
	}
	tmp2 := regexState.FindStringIndex(s)
	if tmp2 == nil && tmp == nil {
		log.Debug("no state found AND no zip found")
		return &dt.Address{}, ErrInvalidAddress
	}
	var city, state string
	if tmp2 != nil {
		state = s[tmp2[0]:tmp2[1]]
		s = s[:tmp2[0]]
		state = strings.Trim(state, ", \n")
		if len(state) > 2 {
			state = strings.ToLower(state)
			state = states[state]
		}
		tmp = regexCity.FindStringIndex(s)
		if tmp == nil {
			log.Debug("no city found")
			return &dt.Address{}, ErrInvalidAddress
		}
		city = s[tmp[0]:tmp[1]]
		s = s[:tmp[0]]
	} else {
		log.Debug("no state found")
	}
	tmp = regexApartment.FindStringIndex(s)
	var apartment string
	if tmp != nil {
		apartment = s[tmp[0]:tmp[1]]
		s2 := s[:tmp[0]]
		if len(s2) == 0 {
			apartment = ""
		} else {
			s = s2
		}
	} else {
		log.Debug("no apartment found")
	}
	tmp = regexStreet.FindStringIndex(s)
	if tmp == nil {
		log.Debug(s)
		log.Debug("no street found")
		return &dt.Address{}, ErrInvalidAddress
	}
	street := s[tmp[0]:tmp[1]]
	return &dt.Address{
		Line1:   strings.Trim(street, " \n,"),
		Line2:   strings.Trim(apartment, " \n,"),
		City:    strings.Trim(city, " \n,"),
		State:   strings.Trim(state, " \n,"),
		Zip:     strings.Trim(zip, " \n,"),
		Country: "USA",
	}, nil
}
1155613
func Parse(cache bool, data ...[]byte) (TemplateChain, error) {
	templates := make(TemplateChain, len(data))
	for index, d := range data {
		template, err := parseOne(cache, d)
		if err != nil {
			return nil, err
		}
		templates[index] = template
	}
	return templates, nil
}
459749
func Parse(input string) (*UPID, error) {
	upid := new(UPID)

	splits := strings.Split(input, "@")
	if len(splits) != 2 {
		return nil, fmt.Errorf("Expect one `@' in the input")
	}
	upid.ID = splits[0]

	if _, err := net.ResolveTCPAddr("tcp4", splits[1]); err != nil {
		return nil, err
	}
	upid.Host, upid.Port, _ = net.SplitHostPort(splits[1])
	return upid, nil
}
52530
func (*Bytes) Parse(value string) (i uint64, err error) {
	parts := pattern.FindStringSubmatch(value)
	if len(parts) < 3 {
		return 0, fmt.Errorf("error parsing value=%s", value)
	}
	bytesString := parts[1]
	multiple := parts[2]
	bytes, err := strconv.ParseUint(bytesString, 10, 64)
	if err != nil {
		return
	}

	switch multiple {
	case "B":
		return bytes * B, nil
	case "K", "KB":
		return bytes * KB, nil
	case "M", "MB":
		return bytes * MB, nil
	case "G", "GB":
		return bytes * GB, nil
	case "T", "TB":
		return bytes * TB, nil
	case "P", "PB":
		return bytes * PB, nil
	}

	return
}
116345
func (h *Hostsfile) parse(r io.Reader, override *hostsMap) *hostsMap {
	hmap := newHostsMap()

	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		line := scanner.Bytes()
		if i := bytes.Index(line, []byte{'#'}); i >= 0 {
			// Discard comments.
			line = line[0:i]
		}
		f := bytes.Fields(line)
		if len(f) < 2 {
			continue
		}
		addr := parseLiteralIP(string(f[0]))
		if addr == nil {
			continue
		}
		ver := ipVersion(string(f[0]))
		for i := 1; i < len(f); i++ {
			name := absDomainName(string(f[i]))
			if plugin.Zones(h.Origins).Matches(name) == "" {
				// name is not in Origins
				continue
			}
			switch ver {
			case 4:
				hmap.byNameV4[name] = append(hmap.byNameV4[name], addr)
			case 6:
				hmap.byNameV6[name] = append(hmap.byNameV6[name], addr)
			default:
				continue
			}
			hmap.byAddr[addr.String()] = append(hmap.byAddr[addr.String()], name)
		}
	}

	if override == nil {
		return hmap
	}

	for name := range override.byNameV4 {
		hmap.byNameV4[name] = append(hmap.byNameV4[name], override.byNameV4[name]...)
	}
	for name := range override.byNameV4 {
		hmap.byNameV6[name] = append(hmap.byNameV6[name], override.byNameV6[name]...)
	}
	for addr := range override.byAddr {
		hmap.byAddr[addr] = append(hmap.byAddr[addr], override.byAddr[addr]...)
	}

	return hmap
}
948667
func Parse(name, text string) (*Parser, error) {
	p := NewParser(name)
	err := p.Parse(text)
	if err != nil {
		p = nil
	}
	return p, err
}
641761
func (n *Name) Parse(reader io.ReadSeeker) error {
	err := encoding.Unmarshal(reader, &n.OffsetPrevString, Endianness)
	if err != nil {
		return err
	}
	err = encoding.Unmarshal(reader, &n.Hash, Endianness)
	if err != nil {
		return err
	}
	err = encoding.Unmarshal(reader, &n.Size, Endianness)
	if err != nil {
		return err
	}

	// No need to control size since it is uint16
	n.UTF16String = make([]uint16, n.Size+1)

	err = encoding.UnmarshaInitSlice(reader, &n.UTF16String, Endianness)
	return err
}
382654
func Parse(ref string) (string, string, error) {
	distributionRef, err := distreference.ParseNamed(ref)
	if err != nil {
		return "", "", err
	}

	tag := GetTagFromNamedRef(distributionRef)
	return distributionRef.Name(), tag, nil
}
473279
func Parse(r io.Reader) (*Template, error) {
	// Create a buffer to copy what we read
	var buf bytes.Buffer
	if _, err := buf.ReadFrom(r); err != nil {
		return nil, err
	}

	// First, decode the object into an interface{}. We do this instead of
	// the rawTemplate directly because we'd rather use mapstructure to
	// decode since it has richer errors.
	var raw interface{}
	if err := json.Unmarshal(buf.Bytes(), &raw); err != nil {
		return nil, err
	}

	// Create our decoder
	var md mapstructure.Metadata
	var rawTpl rawTemplate
	rawTpl.RawContents = buf.Bytes()
	decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
		Metadata: &md,
		Result:   &rawTpl,
	})
	if err != nil {
		return nil, err
	}

	// Do the actual decode into our structure
	if err := decoder.Decode(raw); err != nil {
		return nil, err
	}

	// Build an error if there are unused root level keys
	if len(md.Unused) > 0 {
		sort.Strings(md.Unused)

		unusedMap, ok := raw.(map[string]interface{})
		if !ok {
			return nil, fmt.Errorf("Failed to convert unused root level keys to map")
		}

		for _, unused := range md.Unused {
			if unused[0] == '_' {
				commentVal, ok := unusedMap[unused].(string)
				if !ok {
					return nil, fmt.Errorf("Failed to cast root level comment value to string")
				}

				comment := map[string]string{
					unused: commentVal,
				}

				rawTpl.Comments = append(rawTpl.Comments, comment)
				continue
			}

			err = multierror.Append(err, fmt.Errorf(
				"Unknown root level key in template: '%s'", unused))
		}
	}
	if err != nil {
		return nil, err
	}

	// Return the template parsed from the raw structure
	return rawTpl.Template()
}
1133344
func Parse(s string) (u UUID, err error) {
	if len(s) != 36 {
		return UUID{}, ErrUUIDInvalid
	}

	// create stack addresses for each section of the uuid.
	p := make([][]byte, 5)

	if _, err := fmt.Sscanf(s, format, &p[0], &p[1], &p[2], &p[3], &p[4]); err != nil {
		return u, err
	}

	copy(u[0:4], p[0])
	copy(u[4:6], p[1])
	copy(u[6:8], p[2])
	copy(u[8:10], p[3])
	copy(u[10:16], p[4])

	return
}
1261040
func Parse(source string) (*Template, error) {
	tpl := newTemplate(source)

	// parse template
	if err := tpl.parse(); err != nil {
		return nil, err
	}

	return tpl, nil
}
347320
func Parse(data string) (map[string]interface{}, error) {
	p, err := parse(data, "", false)
	if err != nil {
		return nil, err
	}
	return p.mapping, nil
}
1332130
func Parse(input string) (*Tree, error) {
	t := NewTree(bytes.NewReader([]byte(input)))
	return t, t.Parse()
}
33864
func Parse(rawtemplate string) (template *UriTemplate, err error) {
	template = new(UriTemplate)
	template.raw = rawtemplate
	split := strings.Split(rawtemplate, "{")
	template.parts = make([]templatePart, len(split)*2-1)
	for i, s := range split {
		if i == 0 {
			if strings.Contains(s, "}") {
				err = errors.New("unexpected }")
				break
			}
			template.parts[i].raw = s
		} else {
			subsplit := strings.Split(s, "}")
			if len(subsplit) != 2 {
				err = errors.New("malformed template")
				break
			}
			expression := subsplit[0]
			template.parts[i*2-1], err = parseExpression(expression)
			if err != nil {
				break
			}
			template.parts[i*2].raw = subsplit[1]
		}
	}
	if err != nil {
		template = nil
	}
	return template, err
}