mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-13 19:10:39 +00:00
17 lines
624 B
Swift
17 lines
624 B
Swift
import Foundation
|
|
|
|
enum TextSummarySupport {
|
|
static func summarizeLastLine(_ text: String, maxLength: Int = 200) -> String? {
|
|
let lines = text
|
|
.split(whereSeparator: \.isNewline)
|
|
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
|
|
.filter { !$0.isEmpty }
|
|
guard let last = lines.last else { return nil }
|
|
let normalized = last.replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression)
|
|
if normalized.count > maxLength {
|
|
return String(normalized.prefix(maxLength - 1)) + "…"
|
|
}
|
|
return normalized
|
|
}
|
|
}
|