<commit_before>package com.wcaokaze.japanecraft

import com.wcaokaze.json.*
import java.io.File
import java.io.IOException
import net.minecraftforge.common.config.Configuration as ConfigLoader

class Configuration
    private constructor(val romajiTable: Map<String, RomajiConverter.Output>,
                        val chatMsgFormat: String,
                        val timeFormat: String,
                        val kanjiConverterEnabled: Boolean)
{
  companion object {
    fun load(): Configuration {
      val romajiTable = loadRomajiTable(File("config/JapaneCraftRomajiTable.json"))

      loadConfig(File("config/JapaneCraft.cfg")) {
        val chatMsgFormat = it.loadString(
            category = "format",
            key      = "chat",
            default  = "<\$username> \$rawMessage\$n  §b\$convertedMessage",
            comment  = "The format for chat messages")

        val timeFormat = it.loadString(
            category = "format",
            key      = "time",
            default  = "HH:mm:ss",
            comment  = "The format for `\$time` in chat format")

        val kanjiConverterEnabled = it.loadBoolean(
            category = "mode",
            key      = "enableConvertingToKanji",
            default  = true,
            comment  = "Whether to convert hiragana to kanji")

        return Configuration(romajiTable,
                             chatMsgFormat,
                             timeFormat,
                             kanjiConverterEnabled)
      }

      throw AssertionError()
    }

    private inline fun loadConfig
        (file: File, loadOperation: (ConfigLoader) -> Unit)
    {
      val configLoader = ConfigLoader(file)
      configLoader.load()
      loadOperation(configLoader)
      configLoader.save()
    }

    private fun ConfigLoader.loadString(category: String,
                                        key: String,
                                        default: String,
                                        comment: String)
        = getString(key, category, default, comment)

    private fun ConfigLoader.loadBoolean(category: String,
                                         key: String,
                                         default: Boolean,<commit_msg>fixed a bug<commit_after>package com.wcaokaze.japanecraft

import com.wcaokaze.json.*
import java.io.File
import java.io.IOException
import net.minecraftforge.common.config.Configuration as ConfigLoader

class Configuration private constructor() {
  lateinit var romajiTable: Map<String, RomajiConverter.Output>
    private set

  lateinit var chatMsgFormat: String
    private set

  lateinit var timeFormat: String
    private set

  var kanjiConverterEnabled: Boolean = false
    private set

  companion object {
    fun load(): Configuration = Configuration().apply {
      romajiTable = loadRomajiTable(File("config/JapaneCraftRomajiTable.json"))

      loadConfig(File("config/JapaneCraft.cfg")) {
        chatMsgFormat = it.loadString(
            category = "format",
            key      = "chat",
            default  = "<\$username> \$rawMessage\$n  §b\$convertedMessage",
            comment  = "The format for chat messages")

        timeFormat = it.loadString(
            category = "format",
            key      = "time",
            default  = "HH:mm:ss",
            comment  = "The format for `\$time` in chat format")

        kanjiConverterEnabled = it.loadBoolean(
            category = "mode",
            key      = "enableConvertingToKanji",
            default  = true,
            comment  = "Whether to convert hiragana to kanji")
      }
    }

    private inline fun loadConfig
        (file: File, loadOperation: (ConfigLoader) -> Unit)
    {
      val configLoader = ConfigLoader(file)
      configLoader.load()
      loadOperation(configLoader)
      configLoader.save()
    }

    private fun ConfigLoader.loadString(category: String,
                                        key: String,
                                        default: String,
                                        comment: String)
        = getString(key, category, default, comment)

    private fun ConfigLoader.loadBoolean(category: String,
                                         key: String,
                                         default: Boolean,
{'fraction_non_alphanumeric': 0.08300395256916997, 'fraction_numerical': 0.0, 'mean_word_length': 1.7436224489795917, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '825093', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1025, 'n_words': 266}