Created
April 18, 2012 17:04
-
-
Save Rogach/2415053 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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