Skip to content

Commit

Permalink
using platform specific line endings in config file (there ya go, not…
Browse files Browse the repository at this point in the history
…epad users)
  • Loading branch information
fnuecke committed Feb 12, 2014
1 parent b931bae commit 19bd531
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/li/cil/oc/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.typesafe.config.{ConfigRenderOptions, Config, ConfigFactory}
import cpw.mods.fml.common.Loader
import java.io._
import li.cil.oc.util.PackedColor
import org.apache.commons.lang3.StringEscapeUtils
import scala.collection.convert.WrapAsScala._

class Settings(config: Config) {
Expand Down Expand Up @@ -214,14 +215,16 @@ object Settings {
settings = new Settings(config.getConfig("opencomputers"))

val renderSettings = ConfigRenderOptions.defaults.setJson(false).setOriginComments(false)
val nl = sys.props("line.separator")
val nle = StringEscapeUtils.escapeJava(nl)
val out = new PrintWriter(file)
out.write(config.root.render(renderSettings).lines.
// Indent two spaces instead of four.
map(line => """^(\s*)""".r.replaceAllIn(line, m => m.group(1).replace(" ", " "))).
// Finalize the string.
filter(_ != "").mkString("\n").
filter(_ != "").mkString(nl).
// Newline after values.
replaceAll( """((?:\s*#.*\n)(?:\s*[^#\s].*\n)+)""", "$1\n"))
replaceAll(s"((?:\\s*#.*$nle)(?:\\s*[^#\\s].*$nle)+)", "$1" + nl))
out.close()
}
catch {
Expand Down

0 comments on commit 19bd531

Please sign in to comment.