Remove unused code from FoundationExtras.

This commit is contained in:
Brent Simmons 2024-03-20 21:37:53 -07:00
parent 13871495f3
commit 21ca4fe0aa
7 changed files with 2 additions and 162 deletions

View File

@ -21,10 +21,4 @@ public extension Calendar {
static func dateIsToday(_ date: Date) -> Bool { static func dateIsToday(_ date: Date) -> Bool {
return cached.isDateInToday(date) return cached.isDateInToday(date)
} }
/// The first moment of today.
static var startOfToday: Date {
cached.startOfDay(for: Date())
}
} }

View File

@ -1,21 +0,0 @@
//
// Character+RSCore.swift
// RSCore
//
// Created by Maurice Parker on 4/20/20.
// Copyright © 2020 Ranchero Software, LLC. All rights reserved.
//
import Foundation
public extension Character {
var isSimpleEmoji: Bool {
guard let firstScalar = unicodeScalars.first else { return false }
return firstScalar.properties.isEmoji && firstScalar.value > 0x238C
}
var isCombinedIntoEmoji: Bool { unicodeScalars.count > 1 && unicodeScalars.first?.properties.isEmoji ?? false }
var isEmoji: Bool { isSimpleEmoji || isCombinedIntoEmoji }
}

View File

@ -7,40 +7,15 @@
// //
import Foundation import Foundation
#if canImport(CryptoKit)
import CryptoKit import CryptoKit
#endif
import CommonCrypto
public extension Data { public extension Data {
/// The MD5 hash of the data. /// The MD5 hash of the data.
var md5Hash: Data { var md5Hash: Data {
#if canImport(CryptoKit) let digest = Insecure.MD5.hash(data: self)
if #available(macOS 10.15, *) { return Data(digest)
let digest = Insecure.MD5.hash(data: self)
return Data(digest)
} else {
return ccMD5Hash
}
#else
return ccMD5Hash
#endif
}
@available(macOS, deprecated: 10.15)
@available(iOS, deprecated: 13.0)
private var ccMD5Hash: Data {
let len = Int(CC_MD5_DIGEST_LENGTH)
let md = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: len)
let _ = self.withUnsafeBytes {
CC_MD5($0.baseAddress, numericCast($0.count), md)
}
return Data(bytes: md, count: len)
} }
/// The MD5 has of the data, as a hexadecimal string. /// The MD5 has of the data, as a hexadecimal string.

View File

@ -10,7 +10,6 @@ import Foundation
public extension FileManager { public extension FileManager {
/// Returns whether a path refers to a folder. /// Returns whether a path refers to a folder.
/// ///
/// - Parameter path: The file path to check. /// - Parameter path: The file path to check.
@ -27,35 +26,6 @@ public extension FileManager {
return false return false
} }
/// Copies files from one folder to another, overwriting any existing files with the same name.
///
/// - Parameters:
/// - source: The path of the folder from which to copy files.
/// - destination: The path to the folder at which to place the copied files.
///
/// - Note: This function does not copy files whose names begin with a period.
func copyFiles(fromFolder source: String, toFolder destination: String) throws {
assert(isFolder(atPath: source))
assert(isFolder(atPath: destination))
let sourceURL = URL(fileURLWithPath: source)
let destinationURL = URL(fileURLWithPath: destination)
let filenames = try self.contentsOfDirectory(atPath: source)
for oneFilename in filenames {
if oneFilename.hasPrefix(".") {
continue
}
let sourceFile = sourceURL.appendingPathComponent(oneFilename)
let destinationFile = destinationURL.appendingPathComponent(oneFilename)
try copyFile(atPath: sourceFile.path, toPath: destinationFile.path, overwriting: true)
}
}
/// Retrieve the names of files contained in a folder. /// Retrieve the names of files contained in a folder.
/// ///
/// - Parameter folder: The path to the folder whose contents to retrieve. /// - Parameter folder: The path to the folder whose contents to retrieve.
@ -86,27 +56,4 @@ public extension FileManager {
let url = URL(fileURLWithPath: folder) let url = URL(fileURLWithPath: folder)
return filenames.map { url.appendingPathComponent($0).path } return filenames.map { url.appendingPathComponent($0).path }
} }
}
private extension FileManager {
/// Copies a single file, possibly overwriting any existing file.
///
/// - Parameters:
/// - source: The source path.
/// - destination: The destination path.
/// - overwriting: `true` if an existing file at `destination` should be overwritten.
func copyFile(atPath source: String, toPath destination: String, overwriting: Bool) throws {
assert(fileExists(atPath: source))
if fileExists(atPath: destination) {
if (overwriting) {
try removeItem(atPath: destination)
}
}
try copyItem(atPath: source, toPath: destination)
}
} }

View File

@ -1,32 +0,0 @@
//
// PropertyList.swift
// RSCore
//
// Created by Brent Simmons on 7/12/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
//
import Foundation
// These functions eat errors.
public func propertyList(withData data: Data) -> Any? {
do {
return try PropertyListSerialization.propertyList(from: data, options: [], format: nil)
} catch {
return nil
}
}
// Create a binary plist.
public func data(withPropertyList plist: Any) -> Data? {
do {
return try PropertyListSerialization.data(fromPropertyList: plist, format: .binary, options: 0)
}
catch {
return nil
}
}

View File

@ -10,15 +10,6 @@ import Foundation
public extension Set { public extension Set {
func anyObjectPassingTest( _ test: (Element) -> Bool) -> Element? {
guard let index = self.firstIndex(where: test) else {
return nil
}
return self[index]
}
func anyObject() -> Element? { func anyObject() -> Element? {
if self.isEmpty { if self.isEmpty {

View File

@ -353,17 +353,3 @@ public extension String {
} }
} }
public extension String {
var isSingleEmoji: Bool { count == 1 && containsEmoji }
var containsEmoji: Bool { contains { $0.isEmoji } }
var containsOnlyEmoji: Bool { !isEmpty && !contains { !$0.isEmoji } }
var emojiString: String { emojis.map { String($0) }.reduce("", +) }
var emojis: [Character] { filter { $0.isEmoji } }
var emojiScalars: [UnicodeScalar] { filter { $0.isEmoji }.flatMap { $0.unicodeScalars } }
}