mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 08:17:16 +00:00
Rename forNameCaseInsensitive to forCaseInsensitiveName.
This commit is contained in:
1 parent
114fd2e5c8
commit
fcbc491180
4 files changed
+18
-18
No files matched your search
@@ -13,13 +13,13 @@ enum MediaRSS {
|
||||
/// Attachment from a `media:content` element’s attributes. `url` is the resolved `url` attribute.
|
||||
static func attachment(url: String, attributes: XMLAttributes) -> ParsedAttachment? {
|
||||
|
||||
let mimeType = attributes.value(forNameCaseInsensitive: "type")
|
||||
let mimeType = attributes.value(forCaseInsensitiveName: "type")
|
||||
// The spec says fileSize. Some feeds (atp.fm) use length, as in RSS enclosures.
|
||||
let sizeInBytes = positiveInt(attributes.value(forNameCaseInsensitive: "fileSize") ?? attributes.value(forNameCaseInsensitive: "length"))
|
||||
let durationInSeconds = ParsedAttachment.durationInSeconds(attributes.value(forNameCaseInsensitive: "duration"))
|
||||
let width = positiveInt(attributes.value(forNameCaseInsensitive: "width"))
|
||||
let height = positiveInt(attributes.value(forNameCaseInsensitive: "height"))
|
||||
let mediumValue = attributes.value(forNameCaseInsensitive: "medium")
|
||||
let sizeInBytes = positiveInt(attributes.value(forCaseInsensitiveName: "fileSize") ?? attributes.value(forCaseInsensitiveName: "length"))
|
||||
let durationInSeconds = ParsedAttachment.durationInSeconds(attributes.value(forCaseInsensitiveName: "duration"))
|
||||
let width = positiveInt(attributes.value(forCaseInsensitiveName: "width"))
|
||||
let height = positiveInt(attributes.value(forCaseInsensitiveName: "height"))
|
||||
let mediumValue = attributes.value(forCaseInsensitiveName: "medium")
|
||||
let medium = ParsedAttachment.Medium(mediaRSSValue: mediumValue)
|
||||
|
||||
return ParsedAttachment(url: url, mimeType: mimeType, title: nil, sizeInBytes: sizeInBytes, durationInSeconds: durationInSeconds, width: width, height: height, medium: medium)
|
||||
@@ -38,7 +38,7 @@ enum MediaRSS {
|
||||
}
|
||||
|
||||
static func isDefault(_ attributes: XMLAttributes) -> Bool {
|
||||
attributes.value(forNameCaseInsensitive: "isDefault")?.lowercased() == "true"
|
||||
attributes.value(forCaseInsensitiveName: "isDefault")?.lowercased() == "true"
|
||||
}
|
||||
|
||||
private static func positiveInt(_ s: String?) -> Int? {
|
||||
@@ -78,7 +78,7 @@ struct MediaElementTracker {
|
||||
}
|
||||
|
||||
if localName.equals("content") {
|
||||
if let urlString = attributes.value(forNameCaseInsensitive: "url"), let url = resolveURL(urlString), let attachment = MediaRSS.attachment(url: url, attributes: attributes) {
|
||||
if let urlString = attributes.value(forCaseInsensitiveName: "url"), let url = resolveURL(urlString), let attachment = MediaRSS.attachment(url: url, attributes: attributes) {
|
||||
if group != nil {
|
||||
group?.add(attachment, isDefault: MediaRSS.isDefault(attributes))
|
||||
} else {
|
||||
@@ -100,14 +100,14 @@ struct MediaElementTracker {
|
||||
|
||||
if localName.equals("description") {
|
||||
if item.mediaDescription == nil {
|
||||
item.mediaDescriptionIsHTML = attributes.value(forNameCaseInsensitive: "type")?.lowercased() == "html"
|
||||
item.mediaDescriptionIsHTML = attributes.value(forCaseInsensitiveName: "type")?.lowercased() == "html"
|
||||
parser.beginStoringCharacters()
|
||||
}
|
||||
containerDepth += 1
|
||||
return false
|
||||
}
|
||||
|
||||
if localName.equals("thumbnail"), item.thumbnailURL == nil, let urlString = attributes.value(forNameCaseInsensitive: "url"), !urlString.isEmpty {
|
||||
if localName.equals("thumbnail"), item.thumbnailURL == nil, let urlString = attributes.value(forCaseInsensitiveName: "url"), !urlString.isEmpty {
|
||||
item.thumbnailURL = resolveURL(urlString)
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -101,7 +101,7 @@ private final class RSSDelegate: XMLSAXParserDelegate {
|
||||
return
|
||||
}
|
||||
if parsingArticle && namespace.isITunes && localName.equals("image") {
|
||||
if let currentItem, currentItem.itunesImageURL == nil, let href = attributes.value(forNameCaseInsensitive: "href"), !href.isEmpty {
|
||||
if let currentItem, currentItem.itunesImageURL == nil, let href = attributes.value(forCaseInsensitiveName: "href"), !href.isEmpty {
|
||||
currentItem.itunesImageURL = resolveURL(href)
|
||||
}
|
||||
namespaceElementDepth = 1
|
||||
|
||||
@@ -61,7 +61,7 @@ public struct XMLAttributes: Sendable {
|
||||
}
|
||||
|
||||
/// For feeds with messed up casing (`isPermaLink` vs `ispermalink`).
|
||||
public func value(forNameCaseInsensitive name: String) -> String? {
|
||||
public func value(forCaseInsensitiveName name: String) -> String? {
|
||||
value(forName: name, caseInsensitive: true)
|
||||
}
|
||||
|
||||
|
||||
@@ -116,22 +116,22 @@ import Testing
|
||||
@Test func caseInsensitiveMatchesMixedCaseLocalName() {
|
||||
// RSS's `isPermaLink` vs authors typing `ispermalink`.
|
||||
let a = make(makeAttribute(localName: "isPermaLink", value: "false"))
|
||||
#expect(a.value(forNameCaseInsensitive: "ispermalink") == "false")
|
||||
#expect(a.value(forNameCaseInsensitive: "ISPERMALINK") == "false")
|
||||
#expect(a.value(forNameCaseInsensitive: "IsPermaLink") == "false")
|
||||
#expect(a.value(forCaseInsensitiveName: "ispermalink") == "false")
|
||||
#expect(a.value(forCaseInsensitiveName: "ISPERMALINK") == "false")
|
||||
#expect(a.value(forCaseInsensitiveName: "IsPermaLink") == "false")
|
||||
}
|
||||
|
||||
@Test func caseInsensitiveMatchesPrefixAndLocal() {
|
||||
let a = make(makeAttribute(prefix: "XML", localName: "Lang", value: "en",
|
||||
uri: "http://www.w3.org/XML/1998/namespace"))
|
||||
#expect(a.value(forNameCaseInsensitive: "xml:lang") == "en")
|
||||
#expect(a.value(forCaseInsensitiveName: "xml:lang") == "en")
|
||||
}
|
||||
|
||||
@Test func caseInsensitiveDoesNotAffectNonLetters() {
|
||||
// Hyphens/digits/punctuation compare byte-for-byte even under case-insensitive.
|
||||
let a = make(makeAttribute(localName: "data-id", value: "42"))
|
||||
#expect(a.value(forNameCaseInsensitive: "data-id") == "42")
|
||||
#expect(a.value(forNameCaseInsensitive: "data_id") == nil)
|
||||
#expect(a.value(forCaseInsensitiveName: "data-id") == "42")
|
||||
#expect(a.value(forCaseInsensitiveName: "data_id") == nil)
|
||||
}
|
||||
|
||||
// MARK: - dictionary()
|
||||
|
||||
Reference in new issue
Block a user