chore: set server rules text trimmed before concat

This commit is contained in:
CMK 2021-08-04 15:18:57 +08:00
parent 7165ca5b38
commit 921e850350
1 changed files with 2 additions and 2 deletions

View File

@ -38,7 +38,7 @@ final class MastodonServerRulesViewModel {
let separatorString = Array(repeating: " ", count: 4).joined() let separatorString = Array(repeating: " ", count: 4).joined()
for (i, rule) in rules.enumerated() { for (i, rule) in rules.enumerated() {
guard i < 50 else { guard i < 50 else {
return NSAttributedString(string: "\(i)" + separatorString + rule.text + "\n\n") return NSAttributedString(string: "\(i)" + separatorString + rule.text.trimmingCharacters(in: .whitespacesAndNewlines) + "\n\n")
} }
let imageName = String(i + 1) + ".circle.fill" let imageName = String(i + 1) + ".circle.fill"
let image = UIImage(systemName: imageName, withConfiguration: configuration)! let image = UIImage(systemName: imageName, withConfiguration: configuration)!
@ -47,7 +47,7 @@ final class MastodonServerRulesViewModel {
let imageAttribute = NSMutableAttributedString(attachment: attachment) let imageAttribute = NSMutableAttributedString(attachment: attachment)
imageAttribute.addAttributes([NSAttributedString.Key.baselineOffset : -1.5], range: NSRange(location: 0, length: imageAttribute.length)) imageAttribute.addAttributes([NSAttributedString.Key.baselineOffset : -1.5], range: NSRange(location: 0, length: imageAttribute.length))
let ruleString = NSAttributedString(string: separatorString + rule.text + "\n\n") let ruleString = NSAttributedString(string: separatorString + rule.text.trimmingCharacters(in: .whitespacesAndNewlines) + "\n\n")
attributedString.append(imageAttribute) attributedString.append(imageAttribute)
attributedString.append(ruleString) attributedString.append(ruleString)
} }