| 560 | } |
| 561 | candidate := strings.Join(lines, "\n") |
| 562 | if budget.MaxChars <= 0 { |
| 563 | return "", strings.TrimSpace(candidate) != "" |
| 564 | } |
| 565 | if len([]rune(candidate)) <= budget.MaxChars { |
| 566 | return candidate, truncated |
| 567 | } |
| 568 | if preserveSeparator != nil && strings.Contains(candidate, *preserveSeparator) { |
| 569 | chunks := strings.Split(candidate, *preserveSeparator) |
| 570 | if chunks != nil && len(chunks) > 0 { |
| 571 | current := chunks[0] |
| 572 | if len([]rune(current)) > budget.MaxChars { |
| 573 | return firstRunes(current, budget.MaxChars), true |
| 574 | } |
| 575 | for _, chunk := range chunks[1:] { |