Skip to content

Commit

Permalink
fix saveLines appendLines so that empty and trailing newline is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornregnell committed Jun 11, 2024
1 parent 315e9a2 commit 482dcce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/introprog/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object IO:
* @param enc the encoding of the file.
* */
def saveLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit =
saveString(lines.mkString("\n") + "\n", fileName, enc)
if lines.nonEmpty then saveString(lines.mkString("", "\n", "\n"), fileName, enc)

/**
* Appends `string` to the text file `fileName` using encoding `enc`.
Expand All @@ -78,7 +78,7 @@ object IO:
* @param enc the encoding of the file.
* */
def appendLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit =
appendString(lines.mkString("\n"), fileName, enc)
if lines.nonEmpty then appendString(lines.mkString("","\n","\n"), fileName, enc)

/**
* Load a serialized object from a binary file called `fileName`.
Expand Down

0 comments on commit 482dcce

Please sign in to comment.