mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 20:16:54 +01:00
Continue porting ParserObjC to Swift.
This commit is contained in:
parent
4b646e42c2
commit
d13f0f48ed
@ -14,20 +14,19 @@ let package = Package(
|
|||||||
targets: ["Parser"]),
|
targets: ["Parser"]),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(path: "../ParserObjC"),
|
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||||
.target(
|
.target(
|
||||||
name: "Parser",
|
name: "Parser",
|
||||||
dependencies: ["ParserObjC"],
|
dependencies: [],
|
||||||
swiftSettings: [
|
swiftSettings: [
|
||||||
.enableExperimentalFeature("StrictConcurrency")
|
.enableExperimentalFeature("StrictConcurrency")
|
||||||
]),
|
]),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "ParserTests",
|
name: "ParserTests",
|
||||||
dependencies: ["Parser", "ParserObjC"],
|
dependencies: ["Parser"],
|
||||||
exclude: ["Info.plist"],
|
exclude: ["Info.plist"],
|
||||||
resources: [.copy("Resources")]),
|
resources: [.copy("Resources")]),
|
||||||
]
|
]
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import ParserObjC
|
|
||||||
|
|
||||||
// FeedParser handles RSS, Atom, JSON Feed, and RSS-in-JSON.
|
// FeedParser handles RSS, Atom, JSON Feed, and RSS-in-JSON.
|
||||||
// You don’t need to know the type of feed.
|
// You don’t need to know the type of feed.
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
#if SWIFT_PACKAGE
|
|
||||||
import ParserObjC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public enum FeedType: Sendable {
|
public enum FeedType: Sendable {
|
||||||
case rss
|
case rss
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
#if SWIFT_PACKAGE
|
|
||||||
import ParserObjC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// See https://jsonfeed.org/version/1.1
|
// See https://jsonfeed.org/version/1.1
|
||||||
|
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
#if SWIFT_PACKAGE
|
|
||||||
import ParserObjC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// See https://github.com/scripting/Scripting-News/blob/master/rss-in-json/README.md
|
// See https://github.com/scripting/Scripting-News/blob/master/rss-in-json/README.md
|
||||||
// Also: http://cyber.harvard.edu/rss/rss.html
|
// Also: http://cyber.harvard.edu/rss/rss.html
|
||||||
|
@ -22,6 +22,18 @@ public struct ParsedAuthor: Hashable, Codable, Sendable {
|
|||||||
self.emailAddress = emailAddress
|
self.emailAddress = emailAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Use when the actual property is unknown. Guess based on contents of the string. (This is common with RSS.)
|
||||||
|
convenience init(singleString: String) {
|
||||||
|
|
||||||
|
if singleString.contains("@") {
|
||||||
|
init(name: nil, url: nil, avatarURL: nil, emailAddress: singleString)
|
||||||
|
} else if singleString.lowercased.hasPrefix("http") {
|
||||||
|
init(name: nil, url: singleString, avatarURL: nil, emailAddress: nil)
|
||||||
|
} else {
|
||||||
|
init(name: singleString, url: nil, avatarURL: nil, emailAddress: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Hashable
|
// MARK: - Hashable
|
||||||
|
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
@ -8,10 +8,6 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
#if SWIFT_PACKAGE
|
|
||||||
import ParserObjC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// RSSParser wraps the Objective-C RSAtomParser.
|
// RSSParser wraps the Objective-C RSAtomParser.
|
||||||
//
|
//
|
||||||
// The Objective-C parser creates RSParsedFeed, RSParsedArticle, etc.
|
// The Objective-C parser creates RSParsedFeed, RSParsedArticle, etc.
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
#if SWIFT_PACKAGE
|
|
||||||
import ParserObjC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// RSRSSParser and RSAtomParser were written in Objective-C quite a while ago.
|
// RSRSSParser and RSAtomParser were written in Objective-C quite a while ago.
|
||||||
// They create an RSParsedFeed object and related Objective-C objects.
|
// They create an RSParsedFeed object and related Objective-C objects.
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import ParserObjC
|
|
||||||
|
|
||||||
// RSSParser wraps the Objective-C RSRSSParser.
|
// RSSParser wraps the Objective-C RSRSSParser.
|
||||||
//
|
//
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
//
|
|
||||||
// File.swift
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 4/7/24.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import ParserObjC
|
|
||||||
|
|
||||||
extension ParserData: @unchecked Sendable {}
|
|
19
Modules/Parser/Sources/Parser/ParserData.swift
Normal file
19
Modules/Parser/Sources/Parser/ParserData.swift
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// ParserData.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Brent Simmons on 8/18/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct ParserData: Sendable {
|
||||||
|
|
||||||
|
let url: String
|
||||||
|
let data: Data
|
||||||
|
|
||||||
|
public init(url: String, data: Data) {
|
||||||
|
self.url = url
|
||||||
|
self.data = data
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,5 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import ParserObjC
|
|
||||||
|
|
||||||
extension RSHTMLMetadataParser: @unchecked Sendable {}
|
extension RSHTMLMetadataParser: @unchecked Sendable {}
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
//
|
|
||||||
// FeedParser.h
|
|
||||||
// RSXML
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 7/12/15.
|
|
||||||
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@import Foundation;
|
|
||||||
|
|
||||||
@class RSParsedFeed;
|
|
||||||
@class RSXMLData;
|
|
||||||
|
|
||||||
|
|
||||||
@protocol FeedParser <NSObject>
|
|
||||||
|
|
||||||
+ (BOOL)canParseFeed:(RSXMLData * _Nonnull)xmlData;
|
|
||||||
|
|
||||||
- (nonnull instancetype)initWithXMLData:(RSXMLData * _Nonnull)xmlData;
|
|
||||||
|
|
||||||
- (nullable RSParsedFeed *)parseFeed:(NSError * _Nullable * _Nullable)error;
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
|
@ -1,24 +0,0 @@
|
|||||||
//
|
|
||||||
// ParserData.h
|
|
||||||
// RSParser
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 10/4/17.
|
|
||||||
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@import Foundation;
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
__attribute__((swift_attr("@Sendable")))
|
|
||||||
@interface ParserData : NSObject
|
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSString *url;
|
|
||||||
@property (nonatomic, readonly) NSData *data;
|
|
||||||
|
|
||||||
- (instancetype)initWithURL:(NSString *)url data:(NSData *)data;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
|||||||
//
|
|
||||||
// ParserData.m
|
|
||||||
// RSParser
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 10/4/17.
|
|
||||||
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "ParserData.h"
|
|
||||||
|
|
||||||
@implementation ParserData
|
|
||||||
|
|
||||||
- (instancetype)initWithURL:(NSString *)url data:(NSData *)data {
|
|
||||||
|
|
||||||
self = [super init];
|
|
||||||
if (!self) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
_url = url;
|
|
||||||
_data = data;
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// RSParsedAuthor.h
|
|
||||||
// RSParserTests
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 12/19/17.
|
|
||||||
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@import Foundation;
|
|
||||||
|
|
||||||
@interface RSParsedAuthor : NSObject
|
|
||||||
|
|
||||||
@property (nonatomic, nullable) NSString *name;
|
|
||||||
@property (nonatomic, nullable) NSString *emailAddress;
|
|
||||||
@property (nonatomic, nullable) NSString *url;
|
|
||||||
|
|
||||||
+ (instancetype _Nonnull )authorWithSingleString:(NSString *_Nonnull)s; // Don’t know which property it is. Guess based on contents of the string. Common with RSS.
|
|
||||||
|
|
||||||
@end
|
|
@ -1,34 +0,0 @@
|
|||||||
//
|
|
||||||
// RSParsedAuthor.m
|
|
||||||
// RSParserTests
|
|
||||||
//
|
|
||||||
// Created by Brent Simmons on 12/19/17.
|
|
||||||
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "NSString+RSParser.h"
|
|
||||||
|
|
||||||
#import "RSParsedAuthor.h"
|
|
||||||
|
|
||||||
@implementation RSParsedAuthor
|
|
||||||
|
|
||||||
+ (instancetype)authorWithSingleString:(NSString *)s {
|
|
||||||
|
|
||||||
// The author element in RSS is supposed to be email address — but often it’s a name, and sometimes a URL.
|
|
||||||
|
|
||||||
RSParsedAuthor *author = [[self alloc] init];
|
|
||||||
|
|
||||||
if ([s rsparser_contains:@"@"]) {
|
|
||||||
author.emailAddress = s;
|
|
||||||
}
|
|
||||||
else if ([s.lowercaseString hasPrefix:@"http"]) {
|
|
||||||
author.url = s;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
author.name = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return author;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
Loading…
x
Reference in New Issue
Block a user