// ParseResponseLine parses first response line into ResponseLine struct.
184753
func ParseResponseLine(line []byte) (r ResponseLine, ok bool) {
	var (
		proto  []byte
		status []byte
	)
	proto, status, r.Reason = split3(line, ' ')
	if major, minor, ok := ParseVersion(proto); ok {
		r.Version.Major = major
		r.Version.Minor = minor
	} else {
		return r, false
	}
	if n, ok := IntFromASCII(status); ok {
		r.Status = n
	} else {
		return r, false
	}
	// TODO(gobwas): parse here r.Reason fot TEXT rule:
	//   TEXT = <any OCTET except CTLs,
	//           but including LWS>
	return r, true
}
497031
func (p *GraphiteParser) ParseLine(line string) (telegraf.Metric, error) {
	// Break into 3 fields (name, value, timestamp).
	fields := strings.Fields(line)
	if len(fields) != 2 && len(fields) != 3 {
		return nil, fmt.Errorf("received %q which doesn't have required fields", line)
	}

	// decode the name and tags
	measurement, tags, field, err := p.templateEngine.Apply(fields[0])
	if err != nil {
		return nil, err
	}

	// Could not extract measurement, use the raw value
	if measurement == "" {
		measurement = fields[0]
	}

	// Parse value.
	v, err := strconv.ParseFloat(fields[1], 64)
	if err != nil {
		return nil, fmt.Errorf(`field "%s" value: %s`, fields[0], err)
	}

	if math.IsNaN(v) || math.IsInf(v, 0) {
		return nil, &UnsupposedValueError{Field: fields[0], Value: v}
	}

	fieldValues := map[string]interface{}{}
	if field != "" {
		fieldValues[field] = v
	} else {
		fieldValues["value"] = v
	}

	// If no 3rd field, use now as timestamp
	timestamp := time.Now().UTC()

	if len(fields) == 3 {
		// Parse timestamp.
		unixTime, err := strconv.ParseFloat(fields[2], 64)
		if err != nil {
			return nil, fmt.Errorf(`field "%s" time: %s`, fields[0], err)
		}

		// -1 is a special value that gets converted to current UTC time
		// See https://github.com/graphite-project/carbon/issues/54
		if unixTime != float64(-1) {
			// Check if we have fractional seconds
			timestamp = time.Unix(int64(unixTime), int64((unixTime-math.Floor(unixTime))*float64(time.Second)))
			if timestamp.Before(MinDate) || timestamp.After(MaxDate) {
				return nil, fmt.Errorf("timestamp out of range")
			}
		}
	}
	// Set the default tags on the point if they are not already set
	for k, v := range p.DefaultTags {
		if _, ok := tags[k]; !ok {
			tags[k] = v
		}
	}

	return metric.New(measurement, tags, fieldValues, timestamp)
}
771335
func parseLine(line string) (cmd string, args string) {
  if idx := strings.Index(line, " "); idx > 0 {
    cmd = strings.ToUpper(line[:idx])
    args = strings.TrimSpace(line[idx+1:])
  } else {
    cmd = strings.ToUpper(line)
  }
  return
}
1353965
func (_m *ResponseParser) ParseResponse(channel string, response discovery.ServiceResponse) error {
	ret := _m.Called(channel, response)

	var r0 error
	if rf, ok := ret.Get(0).(func(string, discovery.ServiceResponse) error); ok {
		r0 = rf(channel, response)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
299528
func (i *Image) parseResponse(path string, result interface{}) error {
	errors := make(map[string]error)

	for _, ep := range i.endpoints {
		err := i.parseResponseFromURL(fmt.Sprintf("%s://%s/%s", i.scheme, ep, path), result)
		if err != nil {
			errors[ep] = err
			continue
		}

		return nil
	}

	return combineEndpointErrors(errors)
}
1167386
func (parser *ExtensiveResultParser) ParseResponse(response *SolrResponse, sr *SolrResult) (err error) {
	if resp, ok := response.Response["response"].(map[string]interface{}); ok {
		ParseDocResponse(resp, sr.Results)
	} else {
		err = fmt.Errorf(`Extensive parser can only parse solr response with response object,
					ie response.response and response.response.docs. Or grouped response
					Please use other parser or implement your own parser`)
	}

	return err
}
1258876
func ParseResponse(response *http.Response, mode jsh.DocumentMode) (*jsh.Document, error) {

	skipCodes := []int{
		http.StatusNoContent,
		http.StatusNotFound,
	}

	for _, code := range skipCodes {
		if code == response.StatusCode {
			return nil, nil
		}
	}

	document, err := Document(response, mode)
	if err != nil {
		return nil, err
	}

	return document, nil
}
1064935
func parseResponse(message string) *response {
	r := &response{Headers: url.Values{}, StatusCode: -1}

	parts := strings.SplitN(message, "\n\n", 2)

	for _, line := range strings.Split(parts[0], "\n") {
		if strings.TrimSpace(line) == "" {
			continue
		}

		kv := strings.SplitN(line, ":", 2)

		val := ""
		if len(kv) == 2 {
			val = strings.TrimSpace(kv[1])
		}

		r.Headers.Add(kv[0], val)

		switch kv[0] {
		case "Status-Code":
			i, err := strconv.Atoi(val)
			if err == nil {
				r.StatusCode = i
			}
		case "Status-Text":
			r.StatusText = val
		case "Auth-Sid":
			r.AuthSid = val
		}
	}

	if len(parts) > 1 {
		r.Body = parts[1]
	}

	return r
}
451879
func (operation *Operation) ParseResponseComment(commentLine string, astFile *ast.File) error {
	var matches []string

	if matches = responsePattern.FindStringSubmatch(commentLine); len(matches) != 5 {
		return fmt.Errorf("can not parse response comment \"%s\"", commentLine)
	}

	response := spec.Response{}

	code, _ := strconv.Atoi(matches[1])

	responseDescription := strings.Trim(matches[4], "\"")
	if responseDescription == "" {
		responseDescription = http.StatusText(code)
	}
	response.Description = responseDescription

	schemaType := strings.Trim(matches[2], "{}")
	refType := matches[3]

	if operation.parser != nil { // checking refType has existing in 'TypeDefinitions'
		if err := operation.registerSchemaType(refType, astFile); err != nil {
			return err
		}
	}

	// so we have to know all type in app
	//TODO: we might omitted schema.type if schemaType equals 'object'
	response.Schema = &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{schemaType}}}

	if schemaType == "object" {
		response.Schema.Ref = spec.Ref{
			Ref: jsonreference.MustCreateRef("#/definitions/" + refType),
		}
	}

	if schemaType == "array" {
		refType = TransToValidSchemeType(refType)
		if IsPrimitiveType(refType) {
			response.Schema.Items = &spec.SchemaOrArray{
				Schema: &spec.Schema{
					SchemaProps: spec.SchemaProps{
						Type: spec.StringOrArray{refType},
					},
				},
			}
		} else {
			response.Schema.Items = &spec.SchemaOrArray{
				Schema: &spec.Schema{
					SchemaProps: spec.SchemaProps{
						Ref: spec.Ref{Ref: jsonreference.MustCreateRef("#/definitions/" + refType)},
					},
				},
			}
		}
	}

	if operation.Responses == nil {
		operation.Responses = &spec.Responses{
			ResponsesProps: spec.ResponsesProps{
				StatusCodeResponses: make(map[int]spec.Response),
			},
		}
	}

	operation.Responses.StatusCodeResponses[code] = response

	return nil
}
51365
func parseResponse(xml []byte) (*etree.Document, *etree.Element, error) {
	var doc *etree.Document

	err := maybeDeflate(xml, func(xml []byte) error {
		doc = etree.NewDocument()
		return doc.ReadFromBytes(xml)
	})
	if err != nil {
		return nil, nil, err
	}

	el := doc.Root()
	if el == nil {
		return nil, nil, fmt.Errorf("unable to parse response")
	}

	return doc, el, nil
}
870505
func (c *RPCClient) respondSeq(seq uint64, respHeader *responseHeader) {
	c.dispatchLock.Lock()
	seqL, ok := c.dispatch[seq]
	c.dispatchLock.Unlock()

	// Get a registered listener, ignore if none
	if ok {
		seqL.Handle(respHeader)
	}
}
208308
func ParseLabel(in string) (*Label, error) {
	if len(in) == 0 {
		return &Label{}, nil
	}

	prefix := strings.Split(in, ":")
	segment := prefix[len(prefix)-1]
	if len(prefix) > 0 {
		prefix = prefix[:len(prefix)-1]
	}
	prefixString := strings.Join(prefix, ":")
	if len(prefixString) > 0 {
		prefixString += ":"
	}

	var categories Categories
	for _, s := range strings.Split(segment, ",") {
		if !strings.HasPrefix(s, "c") {
			return nil, fmt.Errorf("categories must start with 'c': %s", segment)
		}
		i, err := strconv.Atoi(s[1:])
		if err != nil {
			return nil, err
		}
		categories = append(categories, uint16(i))
	}
	sort.Sort(categories)

	last := -1
	for _, c := range categories {
		if int(c) == last {
			return nil, fmt.Errorf("labels may not contain duplicate categories: %s", in)
		}
		last = int(c)
	}

	return &Label{
		Prefix:     prefixString,
		Categories: categories,
	}, nil
}
1139717
func ParseResponse(response *http.Response, toks ...Tok) error {
	contentType := response.Header.Get("Content-Type")
	if !IsTextHTML(contentType) {
		return ErrResponseBodyIsNotHTML
	}
	if response.Body == nil {
		return ErrResponseBodyIsEmpty
	}
	r, err := charset.NewReader(response.Body, contentType)
	if err != nil {
		return err
	}
	return ParseReader(r, toks...)
}
1343090
func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {
	r := bytes.NewReader([]byte(line))
	csvReader, err := p.compile(r)
	if err != nil {
		return nil, err
	}

	// if there is nothing in DataColumns, ParseLine will fail
	if len(p.ColumnNames) == 0 {
		return nil, fmt.Errorf("[parsers.csv] data columns must be specified")
	}

	record, err := csvReader.Read()
	if err != nil {
		return nil, err
	}
	m, err := p.parseRecord(record)
	if err != nil {
		return nil, err
	}
	return m, nil
}
645617
func DecodeResponse(lines []string, v interface{}) error {
	if len(lines) > 1 {
		return NewInvalidResponseError("too many lines", lines)
	} else if len(lines) == 0 {
		return NewInvalidResponseError("no lines", lines)
	}

	input := make(map[string]interface{})
	value := reflect.ValueOf(v)
	var slice reflect.Value
	var elemType reflect.Type
	if value.Kind() == reflect.Ptr {
		slice = value.Elem()
		if slice.Kind() == reflect.Slice {
			elemType = slice.Type().Elem()
		}
	}

	for _, part := range strings.Split(lines[0], "|") {
		for _, val := range strings.Split(part, " ") {
			parts := strings.SplitN(val, "=", 2)
			// TODO(steve): support groups
			key := Decode(parts[0])
			if len(parts) == 2 {
				v := Decode(parts[1])
				if i, err := strconv.Atoi(v); err != nil {
					input[key] = v
				} else {
					input[key] = i
				}
			} else {
				input[key] = ""
			}
		}

		if elemType != nil {
			// Expecting a slice
			if err := decodeSlice(elemType, slice, input); err != nil {
				return err
			}

			// Reset the input map
			input = make(map[string]interface{})
		}
	}

	if elemType != nil {
		// Expecting a slice, already decoded
		return nil
	}

	return decodeMap(input, v)
}
422257
func (m *GenericParser) parseLit(val reflect.Value) (Object, error) {
	switch k := val.Kind(); k {
	case reflect.Bool:
		return B(val.Bool()), nil
	case reflect.Int:
		return I(val.Int()), nil
	case reflect.Int8:
		return I8(val.Int()), nil
	case reflect.Int16:
		return I16(val.Int()), nil
	case reflect.Int32:
		return I32(val.Int()), nil
	case reflect.Int64:
		return I64(val.Int()), nil
	case reflect.Uint:
		return U(val.Uint()), nil
	case reflect.Uint8:
		return U8(val.Uint()), nil
	case reflect.Uint16:
		return U16(val.Uint()), nil
	case reflect.Uint32:
		return U32(val.Uint()), nil
	case reflect.Uint64:
		return U64(val.Uint()), nil
	case reflect.Float32:
		return F32(val.Float()), nil
	case reflect.Float64:
		return F64(val.Float()), nil
	case reflect.Complex64:
		m.Stats.Count("parser.parseLit."+k.String(), 1, 1)
		return nil, errors.New("unsupported kind of literal Complex64")
	case reflect.Complex128:
		m.Stats.Count("parser.parseLit."+k.String(), 1, 1)
		return nil, errors.New("unsupported kind of literal Complex128")
	case reflect.Array, reflect.Slice:
		m.Stats.Count("parser.parseLit."+k.String(), 1, 1)
		return nil, errors.New("nested slices/arrays of literals are not supported - parseLit should not be called with these kinds of values")
	case reflect.String:
		return S(val.String()), nil
	default:
		m.Stats.Count("parser.parseLit."+k.String(), 1, 1)
		return nil, errors.Errorf("kind %v is not supported", val.Kind())
	}
}
472389
func ParseLine(line string) (Hostlist, error) {
	var hostnames Hostlist

	if len(line) == 0 {
		return hostnames, fmt.Errorf("line is blank")
	}

	// Parse leading # for disabled lines
	enabled := true
	if line[0:1] == "#" {
		enabled = false
		line = TrimWS(line[1:])
	}

	// Parse other #s for actual comments
	line = strings.Split(line, "#")[0]

	// Replace tabs and multispaces with single spaces throughout
	line = strings.Replace(line, "\t", " ", -1)
	for strings.Contains(line, "  ") {
		line = strings.Replace(line, "  ", " ", -1)
	}
	line = TrimWS(line)

	// Break line into words
	words := strings.Split(line, " ")
	for idx, word := range words {
		words[idx] = TrimWS(word)
	}

	// Separate the first bit (the ip) from the other bits (the domains)
	ip := words[0]
	domains := words[1:]

	// if LooksLikeIPv4(ip) || LooksLikeIPv6(ip) {
	for _, v := range domains {
		hostname, err := NewHostname(v, ip, enabled)
		if err != nil {
			return nil, err
		}
		hostnames = append(hostnames, hostname)
	}
	// }

	return hostnames, nil
}