Add Atom feed detection to FeedType.

This commit is contained in:
Brent Simmons
2024-09-11 21:56:37 -07:00
parent 860ecfd58c
commit 1159d45e5f
2 changed files with 30 additions and 22 deletions

View File

@@ -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)