mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-03 12:27:32 +01:00
Delete unused code in Web module.
This commit is contained in:
parent
01e37824a8
commit
ad61c01ad4
@ -1,39 +0,0 @@
|
||||
//
|
||||
// String+RSWeb.swift
|
||||
// RSWeb
|
||||
//
|
||||
// Created by Brent Simmons on 1/13/18.
|
||||
// Copyright © 2018 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension String {
|
||||
|
||||
/// Escapes special HTML characters.
|
||||
///
|
||||
/// Escaped characters are `&`, `<`, `>`, `"`, and `'`.
|
||||
var escapedHTML: String {
|
||||
var escaped = String()
|
||||
|
||||
for char in self {
|
||||
switch char {
|
||||
case "&":
|
||||
escaped.append("&")
|
||||
case "<":
|
||||
escaped.append("<")
|
||||
case ">":
|
||||
escaped.append(">")
|
||||
case "\"":
|
||||
escaped.append(""")
|
||||
case "'":
|
||||
escaped.append("'")
|
||||
default:
|
||||
escaped.append(char)
|
||||
}
|
||||
}
|
||||
|
||||
return escaped
|
||||
}
|
||||
|
||||
}
|
@ -8,40 +8,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
private struct URLConstants {
|
||||
static let schemeHTTP = "http"
|
||||
static let schemeHTTPS = "https"
|
||||
static let prefixHTTP = "http://"
|
||||
static let prefixHTTPS = "https://"
|
||||
}
|
||||
|
||||
public extension URL {
|
||||
|
||||
func isHTTPSURL() -> Bool {
|
||||
return self.scheme?.lowercased() == URLConstants.schemeHTTPS
|
||||
}
|
||||
|
||||
func isHTTPURL() -> Bool {
|
||||
return self.scheme?.lowercased() == URLConstants.schemeHTTP
|
||||
}
|
||||
|
||||
func isHTTPOrHTTPSURL() -> Bool {
|
||||
return self.isHTTPSURL() || self.isHTTPURL()
|
||||
}
|
||||
|
||||
func absoluteStringWithHTTPOrHTTPSPrefixRemoved() -> String? {
|
||||
// Case-inensitive. Turns http://example.com/foo into example.com/foo
|
||||
|
||||
if isHTTPSURL() {
|
||||
return absoluteString.stringByRemovingCaseInsensitivePrefix(URLConstants.prefixHTTPS)
|
||||
}
|
||||
else if isHTTPURL() {
|
||||
return absoluteString.stringByRemovingCaseInsensitivePrefix(URLConstants.prefixHTTP)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func appendingQueryItem(_ queryItem: URLQueryItem) -> URL? {
|
||||
appendingQueryItems([queryItem])
|
||||
}
|
||||
@ -66,25 +34,4 @@ public extension URL {
|
||||
|
||||
return URL(string: urlString)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension String {
|
||||
|
||||
func stringByRemovingCaseInsensitivePrefix(_ prefix: String) -> String {
|
||||
// Returns self if it doesn’t have the given prefix.
|
||||
|
||||
let lowerPrefix = prefix.lowercased()
|
||||
let lowerSelf = self.lowercased()
|
||||
|
||||
if (lowerSelf == lowerPrefix) {
|
||||
return ""
|
||||
}
|
||||
if !lowerSelf.hasPrefix(lowerPrefix) {
|
||||
return self
|
||||
}
|
||||
|
||||
let index = self.index(self.startIndex, offsetBy: prefix.count)
|
||||
return String(self[..<index])
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
//
|
||||
// NSMutableURLRequest+RSWeb.swift
|
||||
// RSWeb
|
||||
//
|
||||
// Created by Brent Simmons on 12/27/16.
|
||||
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension URLRequest {
|
||||
|
||||
@discardableResult mutating func addBasicAuthorization(username: String, password: String) -> Bool {
|
||||
|
||||
// Do this *only* with https. And not even then if you can help it.
|
||||
|
||||
let s = "\(username):\(password)"
|
||||
guard let d = s.data(using: .utf8, allowLossyConversion: false) else {
|
||||
return false
|
||||
}
|
||||
|
||||
let base64EncodedString = d.base64EncodedString()
|
||||
let authorization = "Basic \(base64EncodedString)"
|
||||
setValue(authorization, forHTTPHeaderField: HTTPRequestHeader.authorization)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user