-
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
Showing
7 changed files
with
51 additions
and
66 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
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
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
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,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)) | ||
} | ||
} |