Skip to content

Commit

Permalink
Fix searchAndReplace: Apply patch only once
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMazur committed Jul 26, 2024
1 parent 4066f70 commit 600b539
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions project-builder/shared/searchAndReplace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ given scala.util.CommandLineParser.FromString[Path] = Paths.get(_)
val input = io.Source.fromFile(file.toFile()).mkString
input
.replace(textOrPattern, replacement)
.pipe: input =>
try textOrPattern.r.replaceAllIn(input, replacement)
catch case _: PatternSyntaxException => input
.pipe: text =>
if text != input then text
else try textOrPattern.r.replaceAllIn(text, replacement)
catch case _: PatternSyntaxException => text
.pipe: output =>
if input != output then
println(s"Successfully applied pattern '$textOrPattern' in $file")
Expand Down

0 comments on commit 600b539

Please sign in to comment.