Skip to content

Commit

Permalink
Now allows blank lines in edits file
Browse files Browse the repository at this point in the history
  • Loading branch information
rchillyard committed Dec 4, 2023
1 parent 7f0b509 commit bd6c26c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/main/scala/com/phasmidsoftware/kmldoc/KMLEdit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
9 changes: 4 additions & 5 deletions src/main/scala/com/phasmidsoftware/kmldoc/KMLEditor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit bd6c26c

Please sign in to comment.