Skip to content

Instantly share code, notes, and snippets.

@Centaur
Created February 8, 2012 14:29
Show Gist options
  • Save Centaur/1770005 to your computer and use it in GitHub Desktop.
Save Centaur/1770005 to your computer and use it in GitHub Desktop.
For Freewind
import collection.mutable.ListBuffer
case class Part(contentType:Option[String], encoding:Option[String], location:Option[String], data:ListBuffer[String])
var boundary: String = null
val Boundary = """.*boundary="(.*)"""".r
var state = 0
val IN_PART = 1
val IN_DATA = 2
var _contentType:Option[String] = None
var _encoding:Option[String] = None
var _location:Option[String] = None
var _data = new ListBuffer[String]()
Source.fromFile("test.mht").getLines.foreach{
case Boundary(b) => boundary = b
case `boundary` =>
_contentType = None
_encoding = None
_location = None
_data = new ListBuffer[String]()
state = IN_PART
case "" => state match {
case IN_PART => state = IN_DATA
case IN_DATA =>
var currentPart = Part(_contentType, _encoding, _location, _data)
/* deal with current Part as allData.last */
case _ =>
}
case line => state match {
case IN_DATA => _data.append(line)
case IN_PART => line.split(":") match {
case Array("Content-Type", t) => _contentType = Some(t)
case Array("Content-Transfer-Encoding", e) => _encoding = Some(e)
case Array("Content-Location", l) => _location = Some(l)
case _ =>
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment