Skip to content

Commit

Permalink
Update Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jihoonahn committed Jan 25, 2024
1 parent 70c83ad commit 57441ca
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 66 deletions.
9 changes: 3 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// swift-tools-version: 5.7
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "plfile",
platforms: [.macOS(.v10_15)],
platforms: [.iOS(.v13), .macOS(.v10_15), .tvOS(.v13), .watchOS(.v6)],
products: [
.library(
name: "File",
Expand All @@ -13,10 +13,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.3.0")
],
targets: [
.target(
name: "File",
dependencies: []
),
.target(name: "File"),
.testTarget(
name: "FileTests",
dependencies: ["File"]
Expand Down
6 changes: 3 additions & 3 deletions Sources/File/Child.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

//MARK: - Child
// MARK: - Child
public extension Folder {
struct ChildSequence<Child: FileSystem> {
let folder: Folder
Expand Down Expand Up @@ -35,7 +35,7 @@ public extension Folder {
}
}

//MARK: - Child Sequence
// MARK: - Child Sequence
extension Folder.ChildSequence: Sequence {
public func makeIterator() -> Folder.ChildIterator<Child> {
return Folder.ChildIterator(
Expand Down Expand Up @@ -79,7 +79,7 @@ public extension Folder.ChildSequence {
}
}

//MARK: - Child Iterator
// MARK: - Child Iterator
extension Folder.ChildIterator: IteratorProtocol {
public mutating func next() -> Child? {
guard index < itemNames.count else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/File/File.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

/// File functionality in PLFile
/// File functionality in PLFile
public struct File: FileSystem {
public var store: Store<File>

Expand All @@ -9,15 +9,15 @@ public struct File: FileSystem {
}
}

/// Property
// MARK: - Property
extension File {
/// PLFile File Type
public static var type: FileType {
return .file
}
}

/// Method
// MARK: - Function
public extension File {
/// write binary data in the file and replace current contexts
func write(_ data: Data) throws {
Expand Down
4 changes: 2 additions & 2 deletions Sources/File/FileError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ extension FileError {
}
}

//MARK: - CustomStringConvertible
// MARK: - CustomStringConvertible
extension FileError: CustomStringConvertible {
/// Representation of `self`
public var description: String {
return String(describing: type(of: self)) + ": (\(message)"
}
}

//MARK: - CustomDebugStringConvertible
// MARK: - CustomDebugStringConvertible
extension FileError: CustomDebugStringConvertible {
/// Representation of instance, suitable for debugging
public var debugDescription: String {
Expand Down
21 changes: 9 additions & 12 deletions Sources/File/Internal/DateExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import Foundation

extension Data {

/**
Converts the `Data` object to a `String` using the specified encoding.
- Parameter encoding: The string encoding to use. Default is `.utf8`.
- Returns: A `String` representation of the `Data` object, or an empty string if the conversion fails.
*/
func stringEncoding(encoding: String.Encoding = .utf8) -> String {
guard let string = String(data: self, encoding: encoding) else { return "" }
return string
}
/// Converts the `Data` object to a `String` using the specified encoding.
///
/// - Parameter encoding: The string encoding to use. Default is `.utf8`.
///
/// - Returns: A `String` representation of the `Data` object, or an empty string if the conversion fails.
func stringEncoding(encoding: String.Encoding = .utf8) -> String {
guard let string = String(data: self, encoding: encoding) else { return "" }
return string
}
}

32 changes: 13 additions & 19 deletions Sources/File/Internal/FileHandleExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import Foundation

extension FileHandle {

/**
Seeks to the end of the file handle.
- Returns: The current offset from the beginning of the file.
- Note: `seekToEndOfFile()` is deprecated in macOS 10.15.4, so this method provides a replacement.
*/
/// Seeks to the end of the file handle.
///
/// - Returns: The current offset from the beginning of the file.
///
/// - Note: `seekToEndOfFile()` is deprecated in macOS 10.15.4, so this method provides a replacement.
func seekToEndFactory() -> UInt64 {
if #available(macOS 10.15.4, *) {
do {
Expand All @@ -21,13 +19,11 @@ extension FileHandle {
}
}

/**
Writes the given data to the file handle.
- Parameter data: The data to write.
- Note: `write(_ data: Data)` is deprecated in macOS 10.15.4, so this method provides a replacement.
*/
/// Writes the given data to the file handle.
///
/// - Parameter data: The data to write.
///
/// - Note: `write(_ data: Data)` is deprecated in macOS 10.15.4, so this method provides a replacement.
func writeFactory(_ data: Data) {
if #available(macOS 10.15.4, *) {
do {
Expand All @@ -40,11 +36,9 @@ extension FileHandle {
}
}

/**
Closes the file handle.
- Note: `closeFile()` is deprecated in macOS 10.15, so this method provides a replacement.
*/
/// Closes the file handle.
///
/// - Note: `closeFile()` is deprecated in macOS 10.15, so this method provides a replacement.
func closeFileFactory() {
if #available(macOS 10.15, *) {
do {
Expand Down
39 changes: 18 additions & 21 deletions Sources/File/Internal/StringExt.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import Foundation

extension String {
/**
Appends a suffix to the string, but only if the string does not already end with that suffix.

- Parameter suffix: The suffix to append.
/// Appends a suffix to the string, but only if the string does not already end with that suffix.
///
/// - Parameter suffix: The suffix to append.
///
/// - Returns: A new string with the suffix appended, or the original string if it already ends with the suffix.
func appendSafeSuffix(_ suffix: String) -> String {
guard !hasSuffix(suffix) else { return self }
return appending(suffix)
}

- Returns: A new string with the suffix appended, or the original string if it already ends with the suffix.
*/
func appendSafeSuffix(_ suffix: String) -> String {
guard !hasSuffix(suffix) else { return self }
return appending(suffix)
}

/**
Removes a prefix from the string, but only if the string starts with that prefix.
- Parameter prefix: The prefix to remove.
- Returns: A new string with the prefix removed, or the original string if it does not start with the prefix.
*/
func removeSafePrefix(_ prefix: String) -> String {
guard hasPrefix(prefix) else { return self }
return String(dropFirst(prefix.count))
}
/// Removes a prefix from the string, but only if the string starts with that prefix.
///
/// - Parameter prefix: The prefix to remove.
///
/// - Returns: A new string with the prefix removed, or the original string if it does not start with the prefix.
func removeSafePrefix(_ prefix: String) -> String {
guard hasPrefix(prefix) else { return self }
return String(dropFirst(prefix.count))
}
}

0 comments on commit 57441ca

Please sign in to comment.