// ParseLinks extracts link relations from the given header value.
482287
func ParseLinks(header string) map[string]string {
	links := map[string]string{}
	if len(header) == 0 {
		return links
	}

	matches := linkRegex.FindAllStringSubmatch(header, -1)
	for _, match := range matches {
		url := match[1]
		rel := match[2]
		links[rel] = url
	}
	return links
}
765271
func ParseKeys(data map[string]interface{}, pairs [][]string) error {
	for _, args := range pairs {
		key, t := args[0], args[1]
		if err := ParseKey(data, key, t); err != nil {
			return err
		}
	}
	return nil
}
81452
func (p *Join) headers(leftHeader []string, rightHeader []string) ([]string, []string, []string, []string) {
	i, a, _ := utils.Intersect(leftHeader, p.LeftKeys)
	_, b, _ := utils.Intersect(rightHeader, p.RightKeys)
	f := make([]string, len(i)+len(a)+len(b))

	copy(f, i)
	copy(f[len(i):], a)
	copy(f[len(i)+len(a):], b)

	return f, i, a, b
}
464297
func (l Links) Href(rel string) (string, error) {
	return l.HrefParams(rel, nil)
}
1139495
func (page *Page) getLinks(text []byte) {
	linksLeft := true

	for linksLeft {
		startTag := []byte("[[")
		startIndex := bytes.Index(text, startTag)

		endTag := []byte("]]")
		endIndex := bytes.Index(text, endTag)

		if startIndex != -1 && endIndex != -1 && startIndex+len(startTag) < endIndex {
			linkBody := text[startIndex+len(startTag) : endIndex]

			pipeIndex := bytes.Index(linkBody, []byte("|"))

			if pipeIndex != -1 {
				linkBody = linkBody[:pipeIndex]
			}

			categoryTag := []byte("Category:")
			categoryIndex := bytes.Index(linkBody, categoryTag)

			if categoryIndex != -1 {
				category := linkBody[len(categoryTag):]

				page.Categories = append(page.Categories, string(category))
			} else {
				if isTitle(linkBody) {
					page.Links = append(page.Links, string(linkBody))
				}
			}

			text = text[endIndex+len(endTag):]
		} else {
			linksLeft = false
		}
	}
}
409958
func (mounter *Mounter) EvalHostSymlinks(pathname string) (string, error) {
	return filepath.EvalSymlinks(pathname)
}
618117
func ParseFiles(fs []string) (*Source, error) {
	src := &Source{
		Funcs: make([]*Fn, 0),
		Files: make([]string, 0),
		StdLibImports: []string{
			"unsafe",
		},
		ExternalImports: make([]string, 0),
	}
	for _, file := range fs {
		if err := src.ParseFile(file); err != nil {
			return nil, err
		}
	}
	return src, nil
}
717795
func (h *HTTPBin) Links(w http.ResponseWriter, r *http.Request) {
	parts := strings.Split(r.URL.Path, "/")
	if len(parts) != 3 && len(parts) != 4 {
		http.Error(w, "Not found", http.StatusNotFound)
		return
	}

	n, err := strconv.Atoi(parts[2])
	if err != nil || n < 0 || n > 256 {
		http.Error(w, "Invalid link count", http.StatusBadRequest)
		return
	}

	// Are we handling /links/<n>/<offset>? If so, render an HTML page
	if len(parts) == 4 {
		offset, err := strconv.Atoi(parts[3])
		if err != nil {
			http.Error(w, "Invalid offset", http.StatusBadRequest)
		}
		doLinksPage(w, r, n, offset)
		return
	}

	// Otherwise, redirect from /links/<n> to /links/<n>/0
	r.URL.Path = r.URL.Path + "/0"
	w.Header().Set("Location", r.URL.String())
	w.WriteHeader(http.StatusFound)
}
157903
func (al HALLinks) Keys() (keys []string) {
	keys = make([]string, len(al.links))
	for i, l := range al.links {
		keys[i] = l.Name
	}
	return
}
1273974
func (c *Sharing) ListSharedLinks(in *ListShareLinksInput) (out *ListShareLinksOutput, err error) {
	endpoint := "/sharing/list_shared_links"
	body, err := c.call(endpoint, in)
	if err != nil {
		return
	}
	defer body.Close()

	err = json.NewDecoder(body).Decode(&out)
	return
}
321811
func (p *Parser) parseSources(subqueries bool) (Sources, error) {
	var sources Sources

	for {
		s, err := p.parseSource(subqueries)
		if err != nil {
			return nil, err
		}
		sources = append(sources, s)

		if tok, _, _ := p.ScanIgnoreWhitespace(); tok != COMMA {
			p.Unscan()
			break
		}
	}

	return sources, nil
}
719814
func (mo *Mo) parseHeaders() {
	// Make sure we end with 2 carriage returns.
	raw := mo.Get("") + "\n\n"

	// Read
	reader := bufio.NewReader(strings.NewReader(raw))
	tp := textproto.NewReader(reader)

	var err error

	// Sync Headers write.
	mo.Lock()
	defer mo.Unlock()

	mo.Headers, err = tp.ReadMIMEHeader()
	if err != nil {
		return
	}

	// Get/save needed headers
	mo.Language = mo.Headers.Get("Language")
	mo.PluralForms = mo.Headers.Get("Plural-Forms")

	// Parse Plural-Forms formula
	if mo.PluralForms == "" {
		return
	}

	// Split plural form header value
	pfs := strings.Split(mo.PluralForms, ";")

	// Parse values
	for _, i := range pfs {
		vs := strings.SplitN(i, "=", 2)
		if len(vs) != 2 {
			continue
		}

		switch strings.TrimSpace(vs[0]) {
		case "nplurals":
			mo.nplurals, _ = strconv.Atoi(vs[1])

		case "plural":
			mo.plural = vs[1]

			if expr, err := plurals.Compile(mo.plural); err == nil {
				mo.pluralforms = expr
			}

		}
	}
}
198367
func HyperHeaderRelations(header http.Header, rels Relations) Relations {
	if rels == nil {
		rels = make(Relations)
	}

	link := header.Get("Link")
	if len(link) == 0 {
		return rels
	}

	for _, l := range strings.Split(link, ",") {
		l = strings.TrimSpace(l)
		segments := strings.Split(l, ";")

		if len(segments) < 2 {
			continue
		}

		if !strings.HasPrefix(segments[0], "<") || !strings.HasSuffix(segments[0], ">") {
			continue
		}

		url, err := url.Parse(segments[0][1 : len(segments[0])-1])
		if err != nil {
			continue
		}

		link := Hyperlink(url.String())

		for _, segment := range segments[1:] {
			switch strings.TrimSpace(segment) {
			case `rel="next"`:
				rels["next"] = link
			case `rel="prev"`:
				rels["prev"] = link
			case `rel="first"`:
				rels["first"] = link
			case `rel="last"`:
				rels["last"] = link
			}
		}
	}

	return rels
}
623307
func ParseSections(r io.Reader) (sections []string, err error) {
	s := bufio.NewScanner(r)

	for s.Scan() {
		t := s.Text()
		if strings.HasPrefix(t, "[") {
			sections = append(sections, strings.Trim(t, "[]"))
		}
	}

	err = s.Err()

	return
}
701030
func ParseLabels(labelSpec interface{}) (map[string]string, error) {
	labelString, isString := labelSpec.(string)
	if !isString {
		return nil, fmt.Errorf("expected string, found %v", labelSpec)
	}
	if len(labelString) == 0 {
		return nil, fmt.Errorf("no label spec passed")
	}
	labels := map[string]string{}
	labelSpecs := strings.Split(labelString, ",")
	for ix := range labelSpecs {
		labelSpec := strings.Split(labelSpecs[ix], "=")
		if len(labelSpec) != 2 {
			return nil, fmt.Errorf("unexpected label spec: %s", labelSpecs[ix])
		}
		if len(labelSpec[0]) == 0 {
			return nil, fmt.Errorf("unexpected empty label key")
		}
		labels[labelSpec[0]] = labelSpec[1]
	}
	return labels, nil
}
456071
func (parser *ExtensiveResultParser) ParseFacets(response *SolrResponse, sr *SolrResult) {
	if fc, ok := response.Response["facet_counts"].(map[string]interface{}); ok {
		sr.FacetCounts = fc
		if f, ok := fc["facet_fields"].(map[string]interface{}); ok {
			sr.Facets = f
		}
	}
}
1070576
func ResolveSymlinks(path string) string {
	if len(path) == 0 {
		return path
	}

	if resolved, err := filepath.EvalSymlinks(path); err == nil {
		return resolved
	}
	return path
}