Update for pending RSCore String updates

This commit is contained in:
Nate Weaver 2020-01-16 20:09:18 -06:00
parent 3c1668c178
commit b35215d03b
24 changed files with 60 additions and 55 deletions

View File

@ -69,10 +69,10 @@ private extension FeedSpecifier {
score = score + 50
}
if urlString.rs_caseInsensitiveContains("comments") {
if urlString.caseInsensitiveContains("comments") {
score = score - 10
}
if urlString.rs_caseInsensitiveContains("rss") {
if urlString.caseInsensitiveContains("rss") {
score = score + 5
}
if urlString.hasSuffix("/feed/") {
@ -81,15 +81,15 @@ private extension FeedSpecifier {
if urlString.hasSuffix("/feed") {
score = score + 4
}
if urlString.rs_caseInsensitiveContains("json") {
if urlString.caseInsensitiveContains("json") {
score = score + 6
}
if let title = title {
if title.rs_caseInsensitiveContains("comments") {
if title.caseInsensitiveContains("comments") {
score = score - 10
}
if title.rs_caseInsensitiveContains("json") {
if title.caseInsensitiveContains("json") {
score = score + 1
}
}

View File

@ -33,7 +33,7 @@ class HTMLFeedFinder {
for oneBodyLink in bodyLinks {
if linkMightBeFeed(oneBodyLink) {
let normalizedURL = oneBodyLink.urlString.rs_normalizedURL()
let normalizedURL = oneBodyLink.urlString.normalizedURL
let oneFeedSpecifier = FeedSpecifier(title: oneBodyLink.text, urlString: normalizedURL, source: .HTMLLink)
addFeedSpecifier(oneFeedSpecifier)
}

View File

@ -183,9 +183,9 @@ extension Folder: OPMLRepresentable {
}
}()
let escapedTitle = nameForDisplay.rs_stringByEscapingSpecialXMLCharacters()
let escapedTitle = nameForDisplay.escapingSpecialXMLCharacters
var s = "<outline text=\"\(escapedTitle)\" title=\"\(escapedTitle)\"\(attrExternalID)>\n"
s = s.rs_string(byPrependingNumberOfTabs: indentLevel)
s = s.prepending(tabCount: indentLevel)
var hasAtLeastOneChild = false
@ -196,11 +196,11 @@ extension Folder: OPMLRepresentable {
if !hasAtLeastOneChild {
s = "<outline text=\"\(escapedTitle)\" title=\"\(escapedTitle)\"\(attrExternalID)/>\n"
s = s.rs_string(byPrependingNumberOfTabs: indentLevel)
s = s.prepending(tabCount: indentLevel)
return s
}
s = s + NSString.rs_string(withNumberOfTabs: indentLevel) + "</outline>\n"
s = s + String(tabCount: indentLevel) + "</outline>\n"
return s
}

View File

@ -125,7 +125,7 @@ private extension OPMLFile {
}
func opmlDocument() -> String {
let escapedTitle = account.nameForDisplay.rs_stringByEscapingSpecialXMLCharacters()
let escapedTitle = account.nameForDisplay.escapingSpecialXMLCharacters
let openingText =
"""
<?xml version="1.0" encoding="UTF-8"?>

View File

@ -43,7 +43,7 @@ public final class WebFeed: Feed, Renamable, Hashable {
}
set {
if let url = newValue, !url.isEmpty {
metadata.homePageURL = url.rs_normalizedURL()
metadata.homePageURL = url.normalizedURL
}
else {
metadata.homePageURL = nil
@ -256,16 +256,16 @@ extension WebFeed: OPMLRepresentable {
if nameToUse == nil {
nameToUse = ""
}
let escapedName = nameToUse!.rs_stringByEscapingSpecialXMLCharacters()
let escapedName = nameToUse!.escapingSpecialXMLCharacters
var escapedHomePageURL = ""
if let homePageURL = homePageURL {
escapedHomePageURL = homePageURL.rs_stringByEscapingSpecialXMLCharacters()
escapedHomePageURL = homePageURL.escapingSpecialXMLCharacters
}
let escapedFeedURL = url.rs_stringByEscapingSpecialXMLCharacters()
let escapedFeedURL = url.escapingSpecialXMLCharacters
var s = "<outline text=\"\(escapedName)\" title=\"\(escapedName)\" description=\"\" type=\"rss\" version=\"RSS\" htmlUrl=\"\(escapedHomePageURL)\" xmlUrl=\"\(escapedFeedURL)\"/>\n"
s = s.rs_string(byPrependingNumberOfTabs: indentLevel)
s = s.prepending(tabCount: indentLevel)
return s
}

View File

@ -26,7 +26,7 @@ public func databaseIDWithString(_ s: String) -> String {
return identifier
}
let identifier = (s as NSString).rs_md5Hash()
let identifier = s.md5HashString
databaseIDCache[s] = identifier
return identifier
}

View File

@ -33,7 +33,7 @@ final class ArticleSearchInfo: Hashable {
lazy var bodyForIndex: String = {
let s = preferredText.rsparser_stringByDecodingHTMLEntities()
return s.rs_string(byStrippingHTML: 0).rs_stringWithCollapsedWhitespace()
return s.strippingHTML().collapsingWhitespace
}()
init(articleID: String, title: String?, contentHTML: String?, contentText: String?, summary: String?, searchRowID: Int?) {

View File

@ -30,7 +30,7 @@ struct CrashLog {
return nil
}
self.content = s
self.contentHash = s.rs_md5Hash()
self.contentHash = s.md5HashString
self.path = path
self.modificationDate = modificationDate
}

View File

@ -99,7 +99,7 @@ private extension AddFeedController {
var urlStringFromPasteboard: String? {
if let urlString = NSPasteboard.urlString(from: NSPasteboard.general) {
return urlString.rs_normalizedURL()
return urlString.normalizedURL
}
return nil
}

View File

@ -36,7 +36,7 @@ class AddFeedWindowController : NSWindowController {
private var userEnteredTitle: String? {
var s = nameTextField.stringValue
s = s.rs_stringWithCollapsedWhitespace()
s = s.collapsingWhitespace
if s.isEmpty {
return nil
}
@ -93,7 +93,7 @@ class AddFeedWindowController : NSWindowController {
@IBAction func addFeed(_ sender: Any?) {
let urlString = urlTextField.stringValue
let normalizedURLString = (urlString as NSString).rs_normalizedURL()
let normalizedURLString = urlString.normalizedURL
if normalizedURLString.isEmpty {
cancelSheet()
@ -130,7 +130,7 @@ class AddFeedWindowController : NSWindowController {
private extension AddFeedWindowController {
private func updateUI() {
addButton.isEnabled = urlTextField.stringValue.rs_stringMayBeURL()
addButton.isEnabled = urlTextField.stringValue.mayBeURL
}
func cancelSheet() {

View File

@ -67,7 +67,7 @@ private extension DetailStatusBarView {
func updateLinkForDisplay() {
if let mouseoverLink = mouseoverLink, !mouseoverLink.isEmpty {
linkForDisplay = (mouseoverLink as NSString).rs_stringByStrippingHTTPOrHTTPSScheme()
linkForDisplay = mouseoverLink.strippingHTTPOrHTTPSScheme
}
else {
linkForDisplay = nil

View File

@ -95,18 +95,18 @@ private struct NNW3Folder {
extension NNW3Folder: OPMLRepresentable {
func OPMLString(indentLevel: Int, allowCustomAttributes: Bool) -> String {
let t = title?.rs_stringByEscapingSpecialXMLCharacters() ?? ""
let t = title?.escapingSpecialXMLCharacters ?? ""
guard let children = children else {
// Empty folder.
return "<outline text=\"\(t)\" title=\"\(t)\" />\n".rs_string(byPrependingNumberOfTabs: indentLevel)
return "<outline text=\"\(t)\" title=\"\(t)\" />\n".prepending(tabCount: indentLevel)
}
var s = "<outline text=\"\(t)\" title=\"\(t)\">\n".rs_string(byPrependingNumberOfTabs: indentLevel)
var s = "<outline text=\"\(t)\" title=\"\(t)\">\n".prepending(tabCount: indentLevel)
for child in children {
s += child.OPMLString(indentLevel: indentLevel + 1)
}
s += "</outline>\n".rs_string(byPrependingNumberOfTabs: indentLevel)
s += "</outline>\n".prepending(tabCount: indentLevel)
return s
}
}
@ -131,12 +131,12 @@ private struct NNW3Feed {
extension NNW3Feed: OPMLRepresentable {
func OPMLString(indentLevel: Int, allowCustomAttributes: Bool) -> String {
let t = title?.rs_stringByEscapingSpecialXMLCharacters() ?? ""
let p = homePageURL?.rs_stringByEscapingSpecialXMLCharacters() ?? ""
let f = feedURL?.rs_stringByEscapingSpecialXMLCharacters() ?? ""
let t = title?.escapingSpecialXMLCharacters ?? ""
let p = homePageURL?.escapingSpecialXMLCharacters ?? ""
let f = feedURL?.escapingSpecialXMLCharacters ?? ""
var s = "<outline text=\"\(t)\" title=\"\(t)\" description=\"\" type=\"rss\" version=\"RSS\" htmlUrl=\"\(p)\" xmlUrl=\"\(f)\"/>\n"
s = s.rs_string(byPrependingNumberOfTabs: indentLevel)
s = s.prepending(tabCount: indentLevel)
return s
}

View File

@ -37,9 +37,9 @@ struct PasteboardWebFeed: Hashable {
let isLocalFeed: Bool
init(url: String, webFeedID: String?, homePageURL: String?, name: String?, editedName: String?, accountID: String?, accountType: AccountType?) {
self.url = url.rs_normalizedURL()
self.url = url.normalizedURL
self.webFeedID = webFeedID
self.homePageURL = homePageURL?.rs_normalizedURL()
self.homePageURL = homePageURL?.normalizedURL
self.name = name
self.editedName = editedName
self.accountID = accountID
@ -93,7 +93,7 @@ struct PasteboardWebFeed: Hashable {
}
if let foundType = pasteboardType {
if let possibleURLString = pasteboardItem.string(forType: foundType) {
if possibleURLString.rs_stringMayBeURL() {
if possibleURLString.mayBeURL {
self.init(url: possibleURLString, webFeedID: nil, homePageURL: nil, name: nil, editedName: nil, accountID: nil, accountType: nil)
return
}

View File

@ -78,7 +78,7 @@ private extension ArticlePasteboardWriter {
s += "\(summary)\n\n"
}
else if let html = article.contentHTML {
let convertedHTML = html.rs_stringByConvertingToPlainText()
let convertedHTML = html.convertingToPlainText()
s += "\(convertedHTML)\n\n"
}

View File

@ -177,7 +177,7 @@ private struct RSSReader: Hashable {
let name = (path as NSString).lastPathComponent
self.name = name
if name.hasSuffix(".app") {
self.nameMinusAppSuffix = name.rs_string(byStrippingSuffix: ".app", caseSensitive: false)
self.nameMinusAppSuffix = name.stripping(suffix: ".app")
}
else {
self.nameMinusAppSuffix = name

View File

@ -44,8 +44,8 @@ extension AppDelegate : AppDelegateAppleEvents {
return
}
let normalizedURLString = urlString.rs_normalizedURL()
if !normalizedURLString.rs_stringMayBeURL() {
let normalizedURLString = urlString.normalizedURL
if !normalizedURLString.mayBeURL {
return
}

View File

@ -159,7 +159,7 @@ private func filenameWithStyleSuffixRemoved(_ filename: String) -> String {
for oneSuffix in styleSuffixes {
if filename.hasSuffix(oneSuffix) {
return (filename as NSString).rs_string(byStrippingSuffix: oneSuffix, caseSensitive: false)
return filename.stripping(suffix: oneSuffix)
}
}

View File

@ -65,8 +65,8 @@ struct ArticleStringFormatter {
s = s.replacingOccurrences(of: "\r", with: "")
s = s.replacingOccurrences(of: "\t", with: "")
s = s.rsparser_stringByDecodingHTMLEntities()
s = s.rs_stringByTrimmingWhitespace()
s = s.rs_stringWithCollapsedWhitespace()
s = s.trimmingWhitespace
s = s.collapsingWhitespace
let maxLength = 1000
if s.count < maxLength {
@ -89,9 +89,9 @@ struct ArticleStringFormatter {
return cachedBody
}
var s = body.rsparser_stringByDecodingHTMLEntities()
s = s.rs_string(byStrippingHTML: 250)
s = s.rs_stringByTrimmingWhitespace()
s = s.rs_stringWithCollapsedWhitespace()
s = s.strippingHTML(maxCharacters: 250)
s = s.trimmingWhitespace
s = s.collapsingWhitespace
if s == "Comments" { // Hacker News.
s = ""
}

View File

@ -14,7 +14,7 @@ struct OPMLExporter {
static func OPMLString(with account: Account, title: String) -> String {
let escapedTitle = title.rs_stringByEscapingSpecialXMLCharacters()
let escapedTitle = title.escapingSpecialXMLCharacters
let openingText =
"""
<?xml version="1.0" encoding="UTF-8"?>

View File

@ -6,7 +6,12 @@
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Foundation
#if os(macOS)
import AppKit
#else
import UIKit
#endif
import RSCore
extension RSImage {

View File

@ -114,7 +114,7 @@ final class FaviconDownloader {
func favicon(withHomePageURL homePageURL: String) -> IconImage? {
let url = homePageURL.rs_normalizedURL()
let url = homePageURL.normalizedURL
if let url = URL(string: homePageURL) {
if url.host == "nnw.ranchero.com" {

View File

@ -34,7 +34,7 @@ final class SingleFaviconDownloader {
private let queue: DispatchQueue
private var diskKey: String {
return (faviconURL as NSString).rs_md5Hash()
return faviconURL.md5HashString
}
init(faviconURL: String, homePageURL: String?, diskCache: BinaryDiskCache, queue: DispatchQueue) {

View File

@ -128,7 +128,7 @@ private extension ImageDownloader {
func diskKey(_ url: String) -> String {
return (url as NSString).rs_md5Hash()
return url.md5HashString
}
func postImageDidBecomeAvailableNotification(_ url: String) {

View File

@ -30,9 +30,9 @@ class AddWebFeedViewController: UITableViewController, AddContainerViewControlle
super.viewDidLoad()
if initialFeed == nil, let urlString = UIPasteboard.general.string as NSString? {
if urlString.rs_stringMayBeURL() {
initialFeed = urlString.rs_normalizedURL()
if initialFeed == nil, let urlString = UIPasteboard.general.string {
if urlString.mayBeURL {
initialFeed = urlString.normalizedURL
}
}
@ -73,7 +73,7 @@ class AddWebFeedViewController: UITableViewController, AddContainerViewControlle
func add() {
let urlString = urlTextField.text ?? ""
let normalizedURLString = (urlString as NSString).rs_normalizedURL()
let normalizedURLString = urlString.normalizedURL
guard !normalizedURLString.isEmpty, let url = URL(string: normalizedURLString) else {
delegate?.processingDidCancel()
@ -118,7 +118,7 @@ class AddWebFeedViewController: UITableViewController, AddContainerViewControlle
}
@objc func textDidChange(_ note: Notification) {
delegate?.readyToAdd(state: urlTextField.text?.rs_stringMayBeURL() ?? false)
delegate?.readyToAdd(state: urlTextField.text?.mayBeURL ?? false)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {