func()

in apt/message.go [43:67]


func (m *Message) String() string {
	// Map iteration is unordered. For testing convenience, write alphabetical output.
	sortedKeys := make([]string, len(m.fields))
	i := 0
	for key := range m.fields {
		sortedKeys[i] = key
		i++
	}
	sort.Strings(sortedKeys)

	message := []string{fmt.Sprintf("%d %s", m.code, m.description)}
	for _, key := range sortedKeys {
		for _, val := range m.fields[key] {
			// Messages are allowed to contain newlines, but they must not contain double newlines,
			// nor end in a newline (since this would result in a premature double newline). We'll
			// encode all newlines here as a space instead for simplicity.
			val = newlineRegexp.ReplaceAllString(val, " ")

			message = append(message, fmt.Sprintf("%s: %s", key, val))
		}
	}
	message = append(message, "")
	message = append(message, "") // End with a newline.
	return strings.Join(message, "\n")
}