From bd6c26c26760b455144b861024186011a471054f Mon Sep 17 00:00:00 2001 From: Robin Hillyard Date: Mon, 4 Dec 2023 23:03:45 +0000 Subject: [PATCH] Now allows blank lines in edits file --- src/main/scala/com/phasmidsoftware/kmldoc/KMLEdit.scala | 4 +++- .../scala/com/phasmidsoftware/kmldoc/KMLEditor.scala | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/phasmidsoftware/kmldoc/KMLEdit.scala b/src/main/scala/com/phasmidsoftware/kmldoc/KMLEdit.scala index 9655375..091a2e4 100644 --- a/src/main/scala/com/phasmidsoftware/kmldoc/KMLEdit.scala +++ b/src/main/scala/com/phasmidsoftware/kmldoc/KMLEdit.scala @@ -14,7 +14,9 @@ import scala.util.parsing.combinator.JavaTokenParsers * @param op1 the target of the edit. * @param maybeOp2 the result of the edit. */ -case class KmlEdit(command: String, operands: Int, op1: Element, maybeOp2: Option[Element]) +case class KmlEdit(command: String, operands: Int, op1: Element, maybeOp2: Option[Element]) { + def isValid: Boolean = command.nonEmpty && operands > 0 +} object KmlEdit { diff --git a/src/main/scala/com/phasmidsoftware/kmldoc/KMLEditor.scala b/src/main/scala/com/phasmidsoftware/kmldoc/KMLEditor.scala index b9ee31b..72ace68 100644 --- a/src/main/scala/com/phasmidsoftware/kmldoc/KMLEditor.scala +++ b/src/main/scala/com/phasmidsoftware/kmldoc/KMLEditor.scala @@ -20,7 +20,7 @@ import scala.util._ */ case class KMLEditor(edits: Seq[KmlEdit]) { - KMLEditor.logger.info(s"KMLEditor: ${edits.mkString}") + KMLEditor.logger.info(s"""KMLEditor: ${edits.mkString(", ")}""") /** * Method to process the file defined by baseFilename by parsing it, editing it, and writing it out. @@ -51,7 +51,6 @@ case class KMLEditor(edits: Seq[KmlEdit]) { private def processFromTo(inputFile: Try[String], outputFile: Try[String]): IO[Unit] = { val qsi: IO[Seq[Writer]] = for { w <- IO.fromTry(outputFile) -// _ = println(w) f <- IO(new File(w)) bW = new BufferedWriter(new FileWriter(f, false)) ks <- KMLCompanion.loadKML(inputFile) @@ -101,9 +100,9 @@ object KMLEditor { def parse(wy: Try[String]): IO[KMLEditor] = for { w <- IO.fromTry(wy) s = Source.fromFile(w) - z <- KmlEdit.parseLines(s.getLines()) - q = KMLEditor(z) - } yield q + es <- KmlEdit.parseLines(s.getLines()) + kE = KMLEditor(es filter (_.isValid)) + } yield kE /** * Method to edit a KML file.