diff --git a/Sources/SkipLib/Skip/String.kt b/Sources/SkipLib/Skip/String.kt index 0cffa95..b571d80 100644 --- a/Sources/SkipLib/Skip/String.kt +++ b/Sources/SkipLib/Skip/String.kt @@ -433,6 +433,10 @@ fun String.matches(of: Regex): Array { 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) } diff --git a/Sources/SkipLib/String.swift b/Sources/SkipLib/String.swift index a6489ce..afdd26b 100644 --- a/Sources/SkipLib/String.swift +++ b/Sources/SkipLib/String.swift @@ -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() } diff --git a/Tests/SkipLibTests/RegexTests.swift b/Tests/SkipLibTests/RegexTests.swift index 587c28c..8b4b3e5 100644 --- a/Tests/SkipLibTests/RegexTests.swift +++ b/Tests/SkipLibTests/RegexTests.swift @@ -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"))