mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
38 lines
1008 B
Swift
Executable File
38 lines
1008 B
Swift
Executable File
//
|
|
// NSURL+RSWeb.swift
|
|
// RSWeb
|
|
//
|
|
// Created by Brent Simmons on 12/26/16.
|
|
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public extension URL {
|
|
|
|
func appendingQueryItem(_ queryItem: URLQueryItem) -> URL? {
|
|
appendingQueryItems([queryItem])
|
|
}
|
|
|
|
func appendingQueryItems(_ queryItems: [URLQueryItem]) -> URL? {
|
|
guard var components = URLComponents(url: self, resolvingAgainstBaseURL: false) else {
|
|
return nil
|
|
}
|
|
|
|
var newQueryItems = components.queryItems ?? []
|
|
newQueryItems.append(contentsOf: queryItems)
|
|
components.queryItems = newQueryItems
|
|
|
|
return components.url
|
|
}
|
|
|
|
func preparedForOpeningInBrowser() -> URL? {
|
|
var urlString = absoluteString.replacingOccurrences(of: " ", with: "%20")
|
|
urlString = urlString.replacingOccurrences(of: "^", with: "%5E")
|
|
urlString = urlString.replacingOccurrences(of: "&", with: "&")
|
|
urlString = urlString.replacingOccurrences(of: "&", with: "&")
|
|
|
|
return URL(string: urlString)
|
|
}
|
|
}
|