mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 19:27:30 +03:00
Add .deletingLastExtension to String
This commit is contained in:
parent
f567a7d63d
commit
0033a80c31
@ -25,6 +25,16 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
|
||||
/// The remainder of string after last dot removed.
|
||||
var deletingPathExtension: String {
|
||||
|
||||
self.replacing(/^(.+)\.[^ .]+$/, with: \.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Collection<String> {
|
||||
|
||||
/// Creates a unique name from the receiver's elements by adding the suffix and also a number if needed.
|
||||
|
@ -29,6 +29,18 @@ import Testing
|
||||
|
||||
struct StringFilename {
|
||||
|
||||
@Test func removeExtension() {
|
||||
|
||||
#expect("test".deletingPathExtension == "test")
|
||||
#expect("test.".deletingPathExtension == "test.")
|
||||
#expect("test.txt".deletingPathExtension == "test")
|
||||
#expect("test..txt".deletingPathExtension == "test.")
|
||||
#expect("test.txt.txt".deletingPathExtension == "test.txt")
|
||||
#expect(".htaccess".deletingPathExtension == ".htaccess")
|
||||
#expect("1.2 file".deletingPathExtension == "1.2 file")
|
||||
}
|
||||
|
||||
|
||||
@Test func createAvailableNames() {
|
||||
|
||||
let names = ["foo", "foo 3", "foo copy 3", "foo 4", "foo 7"]
|
||||
|
Loading…
Reference in New Issue
Block a user