// parseParam takes a raw param in the form key="val" and
// returns the key and value as seperate strings
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

}
246552
func (p *parser) parseParameters(elementKind string) (*ast.Parameters, bool, error) {
	_, args, trailingComma, err := p.parseArguments(elementKind)
	if err != nil {
		return nil, false, err
	}
	var params ast.Parameters
	for _, arg := range args.Positional {
		id, ok := astVarToIdentifier(arg)
		if !ok {
			return nil, false, MakeStaticError(fmt.Sprintf("Expected simple identifier but got a complex expression."), *arg.Loc())
		}
		params.Required = append(params.Required, *id)
	}
	for _, arg := range args.Named {
		params.Optional = append(params.Optional, ast.NamedParameter{Name: arg.Name, DefaultArg: arg.Arg})
	}
	return &params, trailingComma, nil
}
1339402
func ParseStringParam(paramString string, info SearchParamInfo) *StringParam {
	return &StringParam{info, unescape(paramString)}
}
839282
func StringParams(params map[string]string) RequestOption {
	return func(req *http.Request) (*http.Request, error) {
		q := req.URL.Query()
		for k, v := range params {
			q.Set(k, v)
		}
		req.URL.RawQuery = q.Encode()
		return req, nil
	}
}
891504
func GetParam(name string, r *http.Request, index ...int) string {
	if params := r.Context().Value(ParamsKey); params != nil {
		params := params.(Params)
		if name != "*" {
			name = ":" + name
		}
		if param := params[name]; param != nil {
			switch param := param.(type) {
			case []string:
				if len(index) > 0 {
					if index[0] < len(param) {
						return param[index[0]]
					}
					return ""
				}
				return param[0]
			default:
				return param.(string)
			}
		}
	}
	return ""
}
597017
func (this *Server) Param(p string, fn func(*Request, *Response, func())) {
	this.Router.AddParamFunc(p, fn)
}
1335071
func decodeParams(arr string) map[string]string {

	p := make(map[string]string)
	var isQuoted = false
	var isParam = true
	var curParam string
	var curVal string
	for _, c := range arr {
		switch {
		// if string is quoted, wait till next quote
		// and capture content
		case c == '"':
			if isQuoted == false {
				isQuoted = true
			} else {
				p[curParam] = curVal
				isQuoted = false
			}
		case c == '=' && isQuoted == false:
			isParam = false
		case c == ';' && isQuoted == false:
			isParam = true
			p[curParam] = curVal
			curParam = ""
			curVal = ""
		default:
			if isParam {
				curParam = curParam + string(c)
			} else {
				curVal = curVal + string(c)
			}
		}
	}
	p[curParam] = curVal
	return p

}
178068
func DecodeParams(src map[string]string) map[string]string {
	results := make(map[string]string, len(src))
	for key, param := range src {
		encoded, err := url.QueryUnescape(param)
		if err != nil {
			encoded = param
		}
		results[key] = encoded
	}
	return results
}
204565
func ParseKeyValueOpt(opt string) (string, string, error) {
	parts := strings.SplitN(opt, "=", 2)
	if len(parts) != 2 {
		return "", "", fmt.Errorf("Unable to parse key/value option: %s", opt)
	}
	return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil
}
172128
func (r *Request) PathParam(key, val string) *Request {
	r.PathParams[key] = val

	return r
}
1133495
func Param(r *http.Request, key string) string {
	p := Params(r)
	if v, ok := p[key]; ok {
		return v
	}
	return ""
}
73745
func (c *Context) Param(name string) string {
	for _, param := range c.params {
		if param.Key == name {
			return param.Value
		}
	}
	return ""
}
1020385
func (cmd *CLI) Params() values.Map {
	params := make(values.Map)
	for param, value := range cmd.paramValues {
		params[param.Name] = value
	}
	return params
}
1362807
func ParseCompositeParam(paramString string, info SearchParamInfo) *CompositeParam {
	return &CompositeParam{info, escapeFriendlySplit(paramString, '$')}
}
761357
func QueryParam(name, value string) Option {
	return optionFunc(func(base string, v url.Values) string {
		v.Set(name, value)
		return base
	})
}
928053
func ParseOrParam(paramStr []string, info SearchParamInfo) *OrParam {
	ors := make([]SearchParam, len(paramStr))
	for i := range paramStr {
		ors[i] = info.CreateSearchParam(paramStr[i])
	}
	return &OrParam{SearchParamInfo{Name: info.Name, Type: "or"}, ors}
}
1180104
func (h *Hook) ParseJSONParameters(headers, query, payload *map[string]interface{}) []error {
	var errors = make([]error, 0)

	for i := range h.JSONStringParameters {
		if arg, ok := h.JSONStringParameters[i].Get(headers, query, payload); ok {
			var newArg map[string]interface{}

			decoder := json.NewDecoder(strings.NewReader(string(arg)))
			decoder.UseNumber()

			err := decoder.Decode(&newArg)

			if err != nil {
				errors = append(errors, &ParseError{err})
				continue
			}

			var source *map[string]interface{}

			switch h.JSONStringParameters[i].Source {
			case SourceHeader:
				source = headers
			case SourcePayload:
				source = payload
			case SourceQuery, SourceQueryAlias:
				source = query
			}

			if source != nil {
				key := h.JSONStringParameters[i].Name

				if h.JSONStringParameters[i].Source == SourceHeader {
					key = textproto.CanonicalMIMEHeaderKey(h.JSONStringParameters[i].Name)
				}

				ReplaceParameter(key, source, newArg)
			} else {
				errors = append(errors, &SourceError{h.JSONStringParameters[i]})
			}
		} else {
			errors = append(errors, &ArgumentError{h.JSONStringParameters[i]})
		}
	}

	if len(errors) > 0 {
		return errors
	}

	return nil
}