@@ -23,10 +23,7 @@ func SplitMessage(content string, maxLen int) []string {
2323 var messages []string
2424
2525 // Dynamic buffer: 10% of maxLen, but at least 50 chars if possible
26- codeBlockBuffer := maxLen / 10
27- if codeBlockBuffer < 50 {
28- codeBlockBuffer = 50
29- }
26+ codeBlockBuffer := max (maxLen / 10 , 50 )
3027 if codeBlockBuffer > maxLen / 2 {
3128 codeBlockBuffer = maxLen / 2
3229 }
@@ -40,10 +37,7 @@ func SplitMessage(content string, maxLen int) []string {
4037 }
4138
4239 // Effective split point: maxLen minus buffer, to leave room for code blocks
43- effectiveLimit := maxLen - codeBlockBuffer
44- if effectiveLimit < maxLen / 2 {
45- effectiveLimit = maxLen / 2
46- }
40+ effectiveLimit := max (maxLen - codeBlockBuffer , maxLen / 2 )
4741
4842 end := start + effectiveLimit
4943
@@ -85,10 +79,9 @@ func SplitMessage(content string, maxLen int) []string {
8579 // If we have a reasonable amount of content after the header, split inside
8680 if msgEnd > headerEndIdx + 20 {
8781 // Find a better split point closer to maxLen
88- innerLimit := start + maxLen - 5 // Leave room for "\n```"
89- if innerLimit > totalLen {
90- innerLimit = totalLen
91- }
82+ innerLimit := min (
83+ // Leave room for "\n```"
84+ start + maxLen - 5 , totalLen )
9285 betterEnd := findLastNewlineInRange (runes , start , innerLimit , 200 )
9386 if betterEnd > headerEndIdx {
9487 msgEnd = betterEnd
@@ -117,10 +110,7 @@ func SplitMessage(content string, maxLen int) []string {
117110 if unclosedIdx - start > 20 {
118111 msgEnd = unclosedIdx
119112 } else {
120- splitAt := start + maxLen - 5
121- if splitAt > totalLen {
122- splitAt = totalLen
123- }
113+ splitAt := min (start + maxLen - 5 , totalLen )
124114 chunk := strings .TrimRight (string (runes [start :splitAt ]), " \t \n \r " ) + "\n ```"
125115 messages = append (messages , chunk )
126116 remaining := strings .TrimSpace (header + "\n " + string (runes [splitAt :totalLen ]))
@@ -196,10 +186,7 @@ func findNewlineFrom(runes []rune, from int) int {
196186// findLastNewlineInRange finds the last newline within the last searchWindow runes
197187// of the range runes[start:end]. Returns the absolute index or start-1 (indicating not found).
198188func findLastNewlineInRange (runes []rune , start , end , searchWindow int ) int {
199- searchStart := end - searchWindow
200- if searchStart < start {
201- searchStart = start
202- }
189+ searchStart := max (end - searchWindow , start )
203190 for i := end - 1 ; i >= searchStart ; i -- {
204191 if runes [i ] == '\n' {
205192 return i
@@ -211,10 +198,7 @@ func findLastNewlineInRange(runes []rune, start, end, searchWindow int) int {
211198// findLastSpaceInRange finds the last space/tab within the last searchWindow runes
212199// of the range runes[start:end]. Returns the absolute index or start-1 (indicating not found).
213200func findLastSpaceInRange (runes []rune , start , end , searchWindow int ) int {
214- searchStart := end - searchWindow
215- if searchStart < start {
216- searchStart = start
217- }
201+ searchStart := max (end - searchWindow , start )
218202 for i := end - 1 ; i >= searchStart ; i -- {
219203 if runes [i ] == ' ' || runes [i ] == '\t' {
220204 return i
0 commit comments