mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add Atom feed detection to FeedType.
This commit is contained in:
@@ -10,7 +10,7 @@ import Foundation
|
||||
import SAX
|
||||
|
||||
public enum FeedType: Sendable {
|
||||
|
||||
|
||||
case rss
|
||||
case atom
|
||||
case jsonFeed
|
||||
@@ -42,6 +42,9 @@ public enum FeedType: Sendable {
|
||||
if isProbablyRSS(cCharPointer, count) {
|
||||
return .rss
|
||||
}
|
||||
if isProbablyAtom(cCharPointer, count) {
|
||||
return .atom
|
||||
}
|
||||
|
||||
return .unknown
|
||||
}
|
||||
@@ -82,6 +85,11 @@ private extension FeedType {
|
||||
return didFindString("<channel>", bytes, count) && didFindString("<pubDate>", bytes, count)
|
||||
}
|
||||
|
||||
static func isProbablyAtom(_ bytes: UnsafePointer<CChar>, _ count: Int) -> Bool {
|
||||
|
||||
didFindString("<feed", bytes, count)
|
||||
}
|
||||
|
||||
static func didFindString(_ string: UnsafePointer<CChar>, _ bytes: UnsafePointer<CChar>, _ numberOfBytes: Int) -> Bool {
|
||||
|
||||
let foundString = strnstr(bytes, string, numberOfBytes)
|
||||
|
||||
@@ -114,27 +114,27 @@ class FeedParserTypeTests: XCTestCase {
|
||||
|
||||
// MARK: Atom
|
||||
|
||||
// func testDaringFireballAtomType() {
|
||||
//
|
||||
// // File extension is .rss, but it’s really an Atom feed.
|
||||
// let d = parserData("DaringFireball", "rss", "http://daringfireball.net/")
|
||||
// let type = feedType(d)
|
||||
// XCTAssertTrue(type == .atom)
|
||||
// }
|
||||
//
|
||||
// func testOneFootTsunamiAtomType() {
|
||||
//
|
||||
// let d = parserData("OneFootTsunami", "atom", "http://onefoottsunami.com/")
|
||||
// let type = feedType(d)
|
||||
// XCTAssertTrue(type == .atom)
|
||||
// }
|
||||
//
|
||||
// func testRussCoxAtomType() {
|
||||
// let d = parserData("russcox", "atom", "https://research.swtch.com/")
|
||||
// let type = feedType(d)
|
||||
// XCTAssertTrue(type == .atom)
|
||||
// }
|
||||
//
|
||||
func testDaringFireballAtomType() {
|
||||
|
||||
// File extension is .rss, but it’s really an Atom feed.
|
||||
let d = parserData("DaringFireball", "rss", "http://daringfireball.net/")
|
||||
let type = FeedType.feedType(d.data)
|
||||
XCTAssertTrue(type == .atom)
|
||||
}
|
||||
|
||||
func testOneFootTsunamiAtomType() {
|
||||
|
||||
let d = parserData("OneFootTsunami", "atom", "http://onefoottsunami.com/")
|
||||
let type = FeedType.feedType(d.data)
|
||||
XCTAssertTrue(type == .atom)
|
||||
}
|
||||
|
||||
func testRussCoxAtomType() {
|
||||
let d = parserData("russcox", "atom", "https://research.swtch.com/")
|
||||
let type = FeedType.feedType(d.data)
|
||||
XCTAssertTrue(type == .atom)
|
||||
}
|
||||
|
||||
// // MARK: RSS-in-JSON
|
||||
//
|
||||
// func testScriptingNewsJSONType() {
|
||||
|
||||
Reference in New Issue
Block a user