mirror of
https://github.com/cranci1/Sora.git
synced 2026-01-11 20:10:24 +00:00
24 lines
697 B
Swift
24 lines
697 B
Swift
//
|
|
// String.swift
|
|
// Sora
|
|
//
|
|
// Created by Francesco on 14/02/25.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension String {
|
|
var strippedHTML: String {
|
|
guard let data = self.data(using: .utf8) else { return self }
|
|
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
|
|
.documentType: NSAttributedString.DocumentType.html,
|
|
.characterEncoding: String.Encoding.utf8.rawValue
|
|
]
|
|
let attributedString = try? NSAttributedString(data: data, options: options, documentAttributes: nil)
|
|
return attributedString?.string ?? self
|
|
}
|
|
|
|
var trimmed: String {
|
|
return self.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
}
|
|
}
|