| 5 | const maxCompactChars = 50_000 |
| 6 | |
| 7 | func TruncateResult(content string, maxChars ...int) string { |
| 8 | limit := maxCompactChars |
| 9 | if len(maxChars) > 0 { |
| 10 | limit = maxChars[0] |
| 11 | } |
| 12 | runes := []rune(content) |
| 13 | if len(runes) <= limit { |
| 14 | return content |
| 15 | } |
| 16 | half := floorDiv(limit, 2) |
| 17 | removed := len(runes) - limit |
| 18 | return string(runes[:pythonSliceEnd(len(runes), half)]) + "\n\n... [" + strconv.Itoa(removed) + " characters truncated] ...\n\n" + string(runes[pythonSliceStart(len(runes), -half):]) |
| 19 | } |
| 20 | |
| 21 | func floorDiv(value, divisor int) int { |
| 22 | result := value / divisor |