diff --git a/src/net/torvald/btex/BTeXParser.kt b/src/net/torvald/btex/BTeXParser.kt index 542b41f34..7a4c355ce 100644 --- a/src/net/torvald/btex/BTeXParser.kt +++ b/src/net/torvald/btex/BTeXParser.kt @@ -806,8 +806,7 @@ object BTeXParser { } } - @OpenTag // reflective access is impossible with 'private' - fun processElemV(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + private fun tagVimpl(attribs: HashMap): String { val hasID = (attribs["id"] != null) val hasFROMGAME = (attribs["fromgame"] != null) @@ -817,18 +816,74 @@ object BTeXParser { else if (hasID) { val it = attribs["id"]!! val value = varMap[it] ?: throw NullPointerException("No variable definition of '$it'") - paragraphBuffer.append(value) + return value } else if (hasFROMGAME) { val it = attribs["fromgame"]!! val value = Lang.get(it, true) - paragraphBuffer.append(value) + return value } else { throw IllegalStateException("One of following attribute required: id, fromgame") } } + @OpenTag // reflective access is impossible with 'private' + fun processElemV(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + paragraphBuffer.append(tagVimpl(attribs)) + } + + @OpenTag // reflective access is impossible with 'private' + fun processElemVEUN(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + vjosa(tagVimpl(attribs), "는", "은") + } + @OpenTag // reflective access is impossible with 'private' + fun processElemVNEUN(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + processElemVEUN(handler, doc, uri, attribs) + } + + @OpenTag // reflective access is impossible with 'private' + fun processElemVI(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + vjosa(tagVimpl(attribs), "가", "이") + } + @OpenTag // reflective access is impossible with 'private' + fun processElemVGA(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + processElemVI(handler, doc, uri, attribs) + } + + @OpenTag // reflective access is impossible with 'private' + fun processElemVEUL(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + vjosa(tagVimpl(attribs), "를", "을") + } + @OpenTag // reflective access is impossible with 'private' + fun processElemVREUL(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + processElemVEUL(handler, doc, uri, attribs) + } + + @OpenTag // reflective access is impossible with 'private' + fun processElemVWA(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + vjosa(tagVimpl(attribs), "와", "과") + } + @OpenTag // reflective access is impossible with 'private' + fun processElemVGWA(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + processElemVWA(handler, doc, uri, attribs) + } + + @OpenTag // reflective access is impossible with 'private' + fun processElemVRO(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + vjosa(tagVimpl(attribs), "로", "으로") + } + @OpenTag // reflective access is impossible with 'private' + fun processElemVEURO(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap) { + processElemVRO(handler, doc, uri, attribs) + } + + @OpenTag // reflective access is impossible with 'private' + private fun vjosa(str: String, josa1: String, josa2: String) { + val value = Lang.getHangulJosa(str, josa1, josa2) + paragraphBuffer.append(value) + } + diff --git a/src/net/torvald/terrarum/langpack/Lang.kt b/src/net/torvald/terrarum/langpack/Lang.kt index 03d3649ad..e1bb8ce03 100644 --- a/src/net/torvald/terrarum/langpack/Lang.kt +++ b/src/net/torvald/terrarum/langpack/Lang.kt @@ -311,36 +311,29 @@ object Lang { } } - fun postEunNeun(word: String): String { + fun getHangulJosa(word: String, josa1: String, josa2: String): String { val lastChar = getLastChar(word) + val isIrregular = josa1.startsWith("로") && josa2.startsWith("으로") - if (isHangul(lastChar)) { + val selected = if (isHangul(lastChar)) { val index = lastChar.toInt() - HANGUL_SYL_START - return if (index % 28 == 0) word + "는" else word + "은" + if (isIrregular) + if (index % 28 == 0 || index % 28 == 8) josa1 else josa2 + else + if (index % 28 == 0) josa1 else josa2 } else if (lastChar in 'A'..'Z' || lastChar in 'a'..'z') { val index = (lastChar.toInt() - 0x41) % 0x20 - return if (HANGUL_POST_INDEX_ALPH[index] == 0) word + "는" else word + "은" + if (isIrregular) + if (HANGUL_POST_RO_INDEX_ALPH[index] == 0) josa1 else josa2 + else + if (HANGUL_POST_INDEX_ALPH[index] == 0) josa1 else josa2 } else { - return "은" + josa2 } - } - fun postIiGa(word: String): String { - val lastChar = getLastChar(word) - - if (isHangul(lastChar)) { - val index = lastChar.toInt() - HANGUL_SYL_START - return if (index % 28 == 0) word + "가" else word + "이" - } - else if (lastChar in 'A'..'Z' || lastChar in 'a'..'z') { - val index = (lastChar.toInt() - 0x41) % 0x20 - return if (HANGUL_POST_INDEX_ALPH[index] == 0) word + "가" else word + "이" - } - else { - return "이" - } + return "$word$selected" } private fun isHangul(c: Char): Boolean { diff --git a/src/net/torvald/terrarum/tests/BTeXTest.kt b/src/net/torvald/terrarum/tests/BTeXTest.kt index 7309134b4..4382a941a 100644 --- a/src/net/torvald/terrarum/tests/BTeXTest.kt +++ b/src/net/torvald/terrarum/tests/BTeXTest.kt @@ -24,8 +24,8 @@ import kotlin.system.measureTimeMillis */ class BTeXTest : ApplicationAdapter() { - val filePath = "btex.xml" -// val filePath = "test.xml" +// val filePath = "btex.xml" + val filePath = "test.xml" // val filePath = "literature/en/daniel_defoe_robinson_crusoe.xml" // val filePath = "literature/ruRU/anton_chekhov_palata_no_6.xml" // val filePath = "literature/koKR/yisang_nalgae.xml"