// ParseForm calls the underlying http.Request ParseForm
// but also adds the URL params to the request Form as if
// they were defined as query params i.e. ?id=13&ok=true but
// does not add the params to the http.Request.URL.RawQuery
// for SEO purposes
976143
func ParseForm(r *http.Request) error {

	if err := r.ParseForm(); err != nil {
		return err
	}

	if rvi := r.Context().Value(defaultContextIdentifier); rvi != nil {

		rv := rvi.(*requestVars)

		if !rv.formParsed {
			for _, p := range rv.params {
				r.Form.Add(p.key, p.value)
			}

			rv.formParsed = true
		}
	}

	return nil
}
1014408
func ParseRef(ref string) (*Ref, error) {
	if ref == "" {
		return nil, trace.BadParameter("missing value")
	}
	parts := strings.FieldsFunc(ref, isDelimiter)
	switch len(parts) {
	case 1:
		shortcut, err := ParseShortcut(parts[0])
		if err != nil {
			return nil, trace.Wrap(err)
		}
		return &Ref{Kind: shortcut}, nil
	case 2:
		shortcut, err := ParseShortcut(parts[0])
		if err != nil {
			return nil, trace.Wrap(err)
		}
		return &Ref{Kind: shortcut, Name: parts[1]}, nil
	}
	return nil, trace.BadParameter("failed to parse '%v'", ref)
}
1260871
func parseValuedParam(param string) (string, *int) {
	re := regexp.MustCompile(`(\w+)([:,](\d+))?`)
	values := re.FindStringSubmatch(param)

	parStr := strings.ToUpper(strings.Trim(values[1], " "))

	// see if the value is supplied
	if len(values) > 3 && strings.Trim(values[3], " ") != "" {
		if value, err := strconv.Atoi(strings.Trim(values[3], " ")); err == nil {
			return parStr, &value
		}
	}

	return parStr, nil
}
585881
func parseForm(r *http.Request) error {
	contentType := r.Header.Get("Content-Type")
	if strings.HasPrefix(contentType, "multipart/form-data") == true {
		return r.ParseMultipartForm(0)
	}
	return r.ParseForm()
}
838604
func (r *Request) MatchParam(key, value string) *Request {
	query := r.URLStruct.Query()
	query.Set(key, value)
	r.URLStruct.RawQuery = query.Encode()
	return r
}
1103209
func Param() HandlerFunc {
	return func(ctx *Context) {
		if action := ctx.Action(); action != nil {
			if p, ok := action.(Paramer); ok {
				p.SetParams(*ctx.Params())
			}
		}
		ctx.Next()
	}
}
443268
func ParseRef(input string) (Ref, error) {
	term, err := ParseTerm(input)
	if err != nil {
		return nil, errors.Wrap(err, "failed to parse ref")
	}
	ref, ok := term.Value.(Ref)
	if !ok {
		return nil, fmt.Errorf("expected ref but got %v", term)
	}
	return ref, nil
}
473518
func Param(req *http.Request, key string) string {
	return C(req).Param(key)
}
401050
func (prs *Parser) Parse(req *http.Request, params imageserver.Params) error {
	crop := req.URL.Query().Get(param)
	if crop == "" {
		return nil
	}
	var minX, minY, maxX, maxY int
	_, err := fmt.Sscanf(crop, "%d,%d|%d,%d", &minX, &minY, &maxX, &maxY)
	if err != nil {
		return &imageserver.ParamError{
			Param:   param,
			Message: fmt.Sprintf("expected format '<int>,<int>|<int>,<int>': %s", err),
		}
	}
	params.Set(param, imageserver.Params{
		"min_x": minX,
		"min_y": minY,
		"max_x": maxX,
		"max_y": maxY,
	})
	return nil
}
1309848
func ParseRequest(req *http.Request) Group {
	if req == nil {
		return nil
	}

	return ParseHeader(req.Header)
}
1114546
func (t *Translator) parseFormat(pattern string, includeDecimalDigits bool) *numberFormat {

	processed := false
	if includeDecimalDigits {
		_, processed = numberFormats[pattern]
	} else {
		_, processed = numberFormatsNoDecimals[pattern]
	}

	if !processed {

		format := new(numberFormat)
		patterns := strings.Split(pattern, ";")

		matches := prefixSuffixRegex.FindAllStringSubmatch(patterns[0], -1)
		if len(matches) > 0 {
			if len(matches[0]) > 1 {
				format.positivePrefix = matches[0][1]
			}
			if len(matches[0]) > 2 {
				format.positiveSuffix = matches[0][2]
			}
		}

		// default values for negative prefix & suffix
		format.negativePrefix = string(t.rules.Numbers.Symbols.Negative) + string(format.positivePrefix)
		format.negativeSuffix = format.positiveSuffix

		// see if they are in the pattern
		if len(patterns) > 1 {
			matches = prefixSuffixRegex.FindAllStringSubmatch(patterns[1], -1)

			if len(matches) > 0 {
				if len(matches[0]) > 1 {
					format.negativePrefix = matches[0][1]
				}
				if len(matches[0]) > 2 {
					format.negativeSuffix = matches[0][2]
				}
			}
		}

		pat := patterns[0]

		if strings.Index(pat, "%") != -1 {
			format.multiplier = 100
		} else if strings.Index(pat, "‰") != -1 {
			format.multiplier = 1000
		} else {
			format.multiplier = 1
		}

		pos := strings.Index(pat, ".")

		if pos != -1 {
			pos2 := strings.LastIndex(pat, "0")
			if pos2 > pos {
				format.minDecimalDigits = pos2 - pos
			}

			pos3 := strings.LastIndex(pat, "#")
			if pos3 >= pos2 {
				format.maxDecimalDigits = pos3 - pos
			} else {
				format.maxDecimalDigits = format.minDecimalDigits
			}

			pat = pat[0:pos]
		}

		p := strings.Replace(pat, ",", "", -1)
		pos = strings.Index(p, "0")
		if pos != -1 {
			format.minIntegerDigits = strings.LastIndex(p, "0") - pos + 1
		}

		p = strings.Replace(pat, "#", "0", -1)
		pos = strings.LastIndex(pat, ",")
		if pos != -1 {
			format.groupSizeFinal = strings.LastIndex(p, "0") - pos
			pos2 := strings.LastIndex(p[0:pos], ",")
			if pos2 != -1 {
				format.groupSizeMain = pos - pos2 - 1
			} else {
				format.groupSizeMain = format.groupSizeFinal
			}
		}

		if includeDecimalDigits {
			numberFormats[pattern] = format
		} else {
			format.maxDecimalDigits = 0
			format.minDecimalDigits = 0
			numberFormatsNoDecimals[pattern] = format
		}

	}

	if includeDecimalDigits {
		return numberFormats[pattern]
	}

	return numberFormatsNoDecimals[pattern]
}
421748
func BuildURLFromMap(baseUrl string, queryParams map[string]string) string {
	if len(queryParams) < 1 {
		return baseUrl
	}
	queryValues := url.Values{}
	for key, val := range queryParams {
		queryValues.Set(key, val)
	}
	return BuildURL(baseUrl, queryValues)
}
771678
func parseParam(raw string) (key, val string) {

	parts := strings.SplitN(raw, "=", 2)
	if len(parts) == 1 {
		return parts[0], ""
	}
	if len(parts) != 2 {
		return "", ""
	}

	key = parts[0]
	val = strings.Trim(parts[1], "\"")

	return key, val

}
12828
func (ps *SourceTransformParser) Parse(req *http.Request, params imageserver.Params) error {
	return parseSourceTransform(ps.Parser, req, params, ps.Transform)
}
490665
func (n Number) parseFormat(pattern string, includeDecimalDigits bool) *numberFormat {
	format := new(numberFormat)
	patterns := strings.Split(pattern, ";")

	matches := prefixSuffixRegex.FindAllStringSubmatch(patterns[0], -1)
	if len(matches) > 0 {
		if len(matches[0]) > 1 {
			format.positivePrefix = matches[0][1]
		}
		if len(matches[0]) > 2 {
			format.positiveSuffix = matches[0][2]
		}
	}

	// default values for negative prefix & suffix
	format.negativePrefix = string(n.Symbols.Negative) + string(format.positivePrefix)
	format.negativeSuffix = format.positiveSuffix

	// see if they are in the pattern
	if len(patterns) > 1 {
		matches = prefixSuffixRegex.FindAllStringSubmatch(patterns[1], -1)

		if len(matches) > 0 {
			if len(matches[0]) > 1 {
				format.negativePrefix = matches[0][1]
			}
			if len(matches[0]) > 2 {
				format.negativeSuffix = matches[0][2]
			}
		}
	}

	pat := patterns[0]

	if strings.Index(pat, "%") != -1 {
		format.multiplier = 100
	} else if strings.Index(pat, "‰") != -1 {
		format.multiplier = 1000
	} else {
		format.multiplier = 1
	}

	pos := strings.Index(pat, ".")

	if pos != -1 {
		pos2 := strings.LastIndex(pat, "0")
		if pos2 > pos {
			format.minDecimalDigits = pos2 - pos
		}

		pos3 := strings.LastIndex(pat, "#")
		if pos3 >= pos2 {
			format.maxDecimalDigits = pos3 - pos
		} else {
			format.maxDecimalDigits = format.minDecimalDigits
		}

		pat = pat[0:pos]
	}

	p := strings.Replace(pat, ",", "", -1)
	pos = strings.Index(p, "0")
	if pos != -1 {
		format.minIntegerDigits = strings.LastIndex(p, "0") - pos + 1
	}

	p = strings.Replace(pat, "#", "0", -1)
	pos = strings.LastIndex(pat, ",")
	if pos != -1 {
		format.groupSizeFinal = strings.LastIndex(p, "0") - pos
		pos2 := strings.LastIndex(p[0:pos], ",")
		if pos2 != -1 {
			format.groupSizeMain = pos - pos2 - 1
		} else {
			format.groupSizeMain = format.groupSizeFinal
		}
	}

	if !includeDecimalDigits {
		format.maxDecimalDigits = 0
		format.minDecimalDigits = 0
	}

	return format
}
415755
func (r *Request) URL() *url.URL {
	u := *r.base
	p := r.path

	if len(r.version) != 0 {
		p = path.Join(p, strings.ToLower(r.version))
	}
	if len(r.resource) != 0 {
		p = path.Join(p, r.resource)
		if len(r.instance) != 0 {
			p = path.Join(p, r.instance)
		}
	}

	u.Path = p

	query := url.Values{}
	for key, values := range r.params {
		for _, value := range values {
			query.Add(key, value)
		}
	}
	if r.timeout != 0 {
		query.Set("timeout", r.timeout.String())
	}
	u.RawQuery = query.Encode()
	return &u
}
15231
func ParseSHAFromURL(url string) (string, error) {
	r, err := http.Get(url)
	if err != nil {
		return "", errors.Wrap(err, "Error downloading checksum.")
	} else if r.StatusCode != http.StatusOK {
		return "", errors.Errorf("Error downloading checksum. Got HTTP Error: %s", r.Status)
	}

	defer r.Body.Close()
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return "", errors.Wrap(err, "Error reading checksum.")
	}

	return strings.Trim(string(body), "\n"), nil
}