-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jihoonahn
committed
Mar 31, 2023
1 parent
6e8f5b3
commit 6e102e8
Showing
5 changed files
with
62 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Foundation | ||
|
||
/// A representation of a file in the library. | ||
public struct PLFile {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
/// PLFile Type | ||
/// The type of a file or folder. | ||
public enum PLFileType { | ||
/// A file. | ||
case file | ||
|
||
/// A folder. | ||
case folder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import Foundation | ||
|
||
extension Data { | ||
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 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import Foundation | ||
|
||
extension String { | ||
func appendSafeSuffix(_ suffix: String) -> String { | ||
guard !hasSuffix(suffix) else { return self } | ||
return appending(suffix) | ||
} | ||
func removeSafePrefix(_ prefix: String) -> String { | ||
guard hasPrefix(prefix) else { return self } | ||
return String(dropFirst(prefix.count)) | ||
} | ||
/** | ||
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) | ||
} | ||
|
||
/** | ||
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)) | ||
} | ||
} |