Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/SkipLib/Skip/String.kt
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ fun String.matches(of: Regex): Array<Regex.Match> {
return of.matches(this)
}

fun String.replacing(other: String, with: String): String {
return replace(oldValue = other, newValue = with)
}

fun String.replacing(regex: Regex, with: String): String {
return regex.replace(this, with)
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/SkipLib/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public struct String: RandomAccessCollection {
fatalError()
}

public func replacing(_ other: String, with: String) -> String {
fatalError()
}

public func replacing(_ regex: Regex, with: String) -> String {
fatalError()
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/SkipLibTests/RegexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Testing
}

@Test func regexReplace() throws {
#expect("X" == "1".replacing("1", with: "X"))
#expect("AX" == "A\\w".replacing("\\w", with: "X"))
#expect("X" == "1".replacing(try Regex("[0-9]"), with: "X"))
#expect("XXX" == "1X1".replacing(try Regex("[0-9]"), with: "X"))
#expect("1Z1" == "1X1".replacing(try Regex("[A-Z]"), with: "Z"))
Expand Down