func extractStringField()

in EVChecker/main.go [235:263]


func extractStringField(r io.RuneReader) (string, error) {
	// consume whitespace up to the opening quote
	b, err := consumeWhiteSpace(r)
	if err != nil {
		return "", errors.Wrap(err, "failed to consume the leading whitespace before a string literal")
	}
	if b != '"' {
		return "", errors.New(fmt.Sprintf(`expected the beginning byte of a string to be an opening quote, but we got a "%s"`, string(b)))
	}
	str := strings.Builder{}
	// consume the string literal
	// This loop does not in any way honor escaped quotes.
	for b, _, err = r.ReadRune(); err == nil && b != '"'; b, _, err = r.ReadRune() {
		str.WriteRune(b) // always returns a nil error
	}
	if err != nil {
		return "", errors.Wrap(err, "failure occurred while consuming a string literal")
	}
	// consume up to the , that delimits struct literal fields.
	// This does not in any way honor the final field omitting this comma.
	b, err = consumeWhiteSpace(r)
	if err != nil {
		return "", errors.Wrap(err, "failed to consume the leading whitespace before the string field delimiter (comma)")
	}
	if b != ',' {
		return "", errors.New(fmt.Sprintf(`expected the final byte of a string field to be a comma, but we got a "%s"`, string(b)))
	}
	return str.String(), nil
}