Don't extract lede if the incoming string is empty

This commit is contained in:
Angelo Stavrow 2020-11-10 15:21:21 -05:00
parent c32c67040f
commit 889faf9351
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -102,21 +102,21 @@ private extension PostListModel {
var lede: String = ""
let sentences = truncatedString.components(separatedBy: terminatingCharacters)
let firstSentence = sentences.filter { !$0.isEmpty }[0]
if truncatedString.count > firstSentence.count {
if terminatingPunctuation.contains(truncatedString[firstSentence.endIndex]) {
lede = String(truncatedString[...firstSentence.endIndex])
} else {
lede = firstSentence
}
} else if truncatedString.count == firstSentence.count {
if string.count > 80 {
if let endOfStringIndex = truncatedString.lastIndex(of: " ") {
lede = truncatedString[..<endOfStringIndex] + ""
if let firstSentence = (sentences.filter { !$0.isEmpty }).first {
if truncatedString.count > firstSentence.count {
if terminatingPunctuation.contains(truncatedString[firstSentence.endIndex]) {
lede = String(truncatedString[...firstSentence.endIndex])
} else {
lede = firstSentence
}
} else if truncatedString.count == firstSentence.count {
if string.count > 80 {
if let endOfStringIndex = truncatedString.lastIndex(of: " ") {
lede = truncatedString[..<endOfStringIndex] + ""
}
} else {
lede = firstSentence
}
} else {
lede = firstSentence
}
}
return lede