func scanPrefixes(reader io.Reader, variables ...string) (map[string]string, error) {
	variablesLeft := len(variables)
	variablesFound := map[string]string{}

	// we use a scanner so we don't have to read it all at once
	scanner := bufio.NewScanner(reader)
	for scanner.Scan() {
		text := scanner.Text()

		// We go through all the variables, checking if it is in this line
		for _, varName := range variables {
			startPos := strings.Index(text, varName+`="`)
			if startPos == -1 {
				continue
			}

			// add the variable length and the `="` to the start
			startPos += len(varName) + 2

			// awesome. so we found the start point!
			// now we find the endPoint...
			endPos := strings.Index(text[startPos+1:], `"`)
			if endPos == -1 {
				// we should always find an end-quote on the same line...
				return nil, errors.New("plugapi: could not find end token for variable " + varName)
			}

			// add it to the map
			variablesFound[varName] = text[startPos : startPos+endPos+1]
			variablesLeft-- // decrement our counter

			if variablesLeft == 0 {
				// break out if we're done finding stuff
				// we use a goto to avoid two checks and breaks (ugly)
				goto FinishedSearching
			}
		}
	}

FinishedSearching:
	// scans stop on error or file finish. let's check for an error
	if err := scanner.Err(); err != nil {
		return nil, err
	}

	// goto is useless because we need an extra check here anyway
	// this returns the actual map if everything was ok
	if variablesLeft == 0 {
		return variablesFound, nil
	}

	return nil, errors.New("plugapi: could not find all variables")
}
// scanPrefixes searches a Reader for variables (well, prefixes)
// and returns a map with the variable name (prefix name) as key
// and the result as the value (result must be enclosed in quotes in the reader)
scanPrefixes searches a Reader for variables (well, prefixes)
and returns a map with the variable name (prefix name) as key
and the result as the value (result must be enclosed in quotes in the reader)
// scanPrefixes searches a Reader for variables ( well prefixes ) // and returns a map with the variable name ( prefix name ) as key // and the result as the value ( result must be enclosed in quotes in the reader )
func scanPrefixes(reader io.Reader, variables ...string) (map[string]string, error) {
	variablesLeft := len(variables)
	variablesFound := map[string]string{}
	scanner := bufio.NewScanner(reader)
	for scanner.Scan() {
		text := scanner.Text()
		for _, varName := range variables {
			startPos := strings.Index(text, varName+`="`)
			if startPos == -1 {
				continue
			}
			startPos += len(varName) + 2
			endPos := strings.Index(text[startPos+1:], `"`)
			if endPos == -1 {
				return nil, errors.New("plugapi: could not find end token for variable " + varName)
			}
			variablesFound[varName] = text[startPos : startPos+endPos+1]
			variablesLeft-- 
			if variablesLeft == 0 {
				goto FinishedSearching
			}
		}
	}
FinishedSearching:
	if err := scanner.Err(); err != nil {
		return nil, err
	}
	if variablesLeft == 0 {
		return variablesFound, nil
	}
	return nil, errors.New("plugapi: could not find all variables")
}
func scanPrefixes ( reader io . Reader , variables ... string ) ( map [ string ] string , error ) { variablesLeft := len ( variables ) variablesFound := map [ string ] string { } scanner := bufio . NewScanner ( reader ) for scanner . Scan ( ) { text := scanner . Text ( ) for _ , varName := range variables { startPos := strings . Index ( text , varName + `="` ) if startPos == - 1 { continue } startPos += len ( varName ) + 2 endPos := strings . Index ( text [ startPos + 1 : ] , `"` ) if endPos == - 1 { return nil , errors . New ( " " + varName ) } variablesFound [ varName ] = text [ startPos : startPos + endPos + 1 ] variablesLeft -- if variablesLeft == 0 { goto FinishedSearching } } } FinishedSearching : if err := scanner . Err ( ) ; err != nil { return nil , err } if variablesLeft == 0 { return variablesFound , nil } return nil , errors . New ( " " ) }
scanPrefixes searches a Reader for variables (well, prefixes)
and returns a map with the variable name (prefix name) as key
and the result as the value (result must be enclosed in quotes in the reader)
scanPrefixes searches a Reader for variables ( well prefixes ) and returns a map with the variable name ( prefix name ) as key and the result as the value ( result must be enclosed in quotes in the reader )
// we use a scanner so we don't have to read it all at once // We go through all the variables, checking if it is in this line // add the variable length and the `="` to the start // awesome. so we found the start point! // now we find the endPoint... // we should always find an end-quote on the same line... // add it to the map // decrement our counter // break out if we're done finding stuff // we use a goto to avoid two checks and breaks (ugly) // scans stop on error or file finish. let's check for an error // goto is useless because we need an extra check here anyway // this returns the actual map if everything was ok