mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Continue progress on AtomParser.
This commit is contained in:
@@ -81,7 +81,7 @@ private extension AtomParser {
|
||||
func addFeedLanguage() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
func addArticle() {
|
||||
let article = RSSArticle(feedURL)
|
||||
articles.append(article)
|
||||
@@ -94,11 +94,7 @@ private extension AtomParser {
|
||||
return
|
||||
}
|
||||
|
||||
let name: String? = {
|
||||
let data = Data(bytes: localName, count: strlen(localName))
|
||||
return String(data: data, encoding: .utf8)
|
||||
}()
|
||||
guard let name else {
|
||||
guard let name = String(xmlPointer: localName) else {
|
||||
assertionFailure("Unexpected failure converting XMLPointer to String in addXHTMLTag.")
|
||||
return
|
||||
}
|
||||
@@ -190,7 +186,20 @@ extension AtomParser: SAXParserDelegate {
|
||||
|
||||
public func saxParser(_ saxParser: SAXParser, xmlCharactersFound: XMLPointer, count: Int) {
|
||||
|
||||
// Required method.
|
||||
guard parsingXHTML else {
|
||||
return
|
||||
}
|
||||
guard var s = String(xmlPointer: xmlCharactersFound, count: count) else {
|
||||
return
|
||||
}
|
||||
|
||||
// libxml decodes all entities; we need to re-encode certain characters
|
||||
// (<, >, and &) when inside XHTML text content.
|
||||
s = s.replacingOccurrences(of: "<", with: "&;lt;")
|
||||
s = s.replacingOccurrences(of: ">", with: "&;gt;")
|
||||
s = s.replacingOccurrences(of: "&", with: "&")
|
||||
|
||||
xhtmlString = s
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,3 +31,11 @@ public func SAXEqualTags(_ localName: XMLPointer, _ tag: ContiguousArray<Int8>)
|
||||
return localName[tagCount - 1] == 0
|
||||
}
|
||||
}
|
||||
|
||||
public extension String {
|
||||
|
||||
init?(xmlPointer: XMLPointer, count: Int? = nil) {
|
||||
let d = Data(bytes: xmlPointer, count: count ?? strlen(xmlPointer))
|
||||
self.init(data: d, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user