All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vvcephei.scalaofx.lib.parser.OfxParser.scala Maven / Gradle / Ivy

There is a newer version: 1.6
Show newest version
package org.vvcephei.scalaofx.lib.parser

import scala.xml.{Elem, XML}

object OfxParser {
  def toXml(ofx: String): Elem =
    XML.loadString(innerToXmlString(OfxLexer.lexAddMissingTags(ofx)).mkString)

  // Pretty dumb that this is a thing...
  def toStrictOfx(elem: Elem): String = innerToXmlString(OfxLexer.lexRemoveOptionalTags(elem.toString)).mkString

  //TODO: Stream processing is probaly better
  private def innerToXmlString(validXml: List[OfxLexicalItem], result: List[String] = Nil): List[String] = validXml match {
    case Nil => result.reverse
    case OpenTag(name) :: rest => innerToXmlString(rest, "<" + name + ">" :: result)
    case CloseTag(name) :: rest => innerToXmlString(rest, "" :: result)
    case Text(text) :: rest => innerToXmlString(rest, text :: result)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy