Skip to content

Instantly share code, notes, and snippets.

@Rogach
Created April 18, 2012 17:04
Show Gist options
  • Save Rogach/2415053 to your computer and use it in GitHub Desktop.
Save Rogach/2415053 to your computer and use it in GitHub Desktop.
def readConfig(lines:List[String]):mutable.Map[String,Map[String,String]] = {
// assuming that *all* properties have their sections
if (lines.isEmpty) Map()
else {
val sectionRgx = """\s*\[(.*)\]\s*""".r
val sectionRgx(sectName) = lines.head
val pairs = lines.tail.takeWhile(!_.startsWith("[")).map(_.split("=")).map(a => (a(0),a(1))).toMap
Map(sectName -> pairs) ++ readConfig(lines.tail.dropWhile(!_.startsWith("["))
}
}
readConfig(io.Source.fromFile("data.ini").getLines.toList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment