From 10f218c175de027fca9361cd2182214235e9df15 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Thu, 16 Apr 2026 21:33:42 -0700 Subject: [PATCH] Support replacing literal strings with literal strings --- Sources/SkipLib/Skip/String.kt | 4 ++++ Sources/SkipLib/String.swift | 4 ++++ Tests/SkipLibTests/RegexTests.swift | 2 ++ 3 files changed, 10 insertions(+) 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"))