Skip to content

Commit

Permalink
Add autoreleasepool to html tags strip with NSAttributesString
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed Mar 22, 2024
1 parent 4b5825a commit 90e28ba
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions MeetingBar/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ extension String {
/// Returns a version of the string with all HTML tags removed, if any.
/// - Returns: The string without HTML tags.
func htmlTagsStripped() -> String {
if containsHTML,
let dataUTF16 = data(using: .utf16),
let attributedSelf = NSAttributedString(
html: dataUTF16,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil
) {
return attributedSelf.string
if !containsHTML {
return self
}
return autoreleasepool {
guard let dataUTF16 = self.data(using: .utf16) else {
return self
}

let attributedString = NSAttributedString(html: dataUTF16, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)

return attributedString?.string ?? self
}
return self
}

func fileName() -> String {
Expand Down

0 comments on commit 90e28ba

Please sign in to comment.