Various Fixes

This commit is contained in:
Ilya Laktyushin
2022-01-10 23:29:14 +03:00
parent 69b36c21f6
commit 9c42eebbbd
12 changed files with 56 additions and 21 deletions

View File

@@ -253,3 +253,20 @@ public func foldLineBreaks(_ text: String) -> String {
}
return result
}
public func trimToLineCount(_ text: String, lineCount: Int) -> String {
if lineCount < 1 {
return ""
}
let lines = text.split { $0.isNewline }
var result = ""
for line in lines.prefix(lineCount) {
if !result.isEmpty {
result += "\n"
}
result += line
}
return result
}