Return Sequence instead of List #6
@ -1,12 +1,12 @@
|
|||||||
package com.marvinelsen.cedict.api
|
package com.marvinelsen.cedict.api
|
||||||
|
|
||||||
import com.marvinelsen.cedict.internal.CedictParserImpl
|
import com.marvinelsen.cedict.internal.RegexCedictParser
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
interface CedictParser {
|
interface CedictParser {
|
||||||
fun parseCedict(inputStream: InputStream): Sequence<CedictEntry>
|
fun parseCedict(inputStream: InputStream): Sequence<CedictEntry>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val instance: CedictParser by lazy { CedictParserImpl() }
|
val instance: CedictParser by lazy { RegexCedictParser() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import com.marvinelsen.cedict.api.CedictParser
|
|||||||
import com.marvinelsen.chinese.transliteration.Syllable
|
import com.marvinelsen.chinese.transliteration.Syllable
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
internal class CedictParserImpl : CedictParser {
|
internal class RegexCedictParser : CedictParser {
|
||||||
companion object {
|
companion object {
|
||||||
private const val DEFINITION_SEPARATOR = '/'
|
private const val DEFINITION_SEPARATOR = '/'
|
||||||
private const val GLOSS_SEPARATOR = ';'
|
private const val GLOSS_SEPARATOR = ';'
|
@ -9,7 +9,7 @@ import java.util.zip.GZIPInputStream
|
|||||||
|
|
||||||
class CedictParserImplTest : ShouldSpec({
|
class CedictParserImplTest : ShouldSpec({
|
||||||
should("parse lines correctly") {
|
should("parse lines correctly") {
|
||||||
val cedictParser = CedictParserImpl()
|
val cedictParser = RegexCedictParser()
|
||||||
val cedictEntry =
|
val cedictEntry =
|
||||||
cedictParser.toCedictEntry("皮實 皮实 [pi2 shi5] /(of things) durable/(of people) sturdy; tough/")
|
cedictParser.toCedictEntry("皮實 皮实 [pi2 shi5] /(of things) durable/(of people) sturdy; tough/")
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ class CedictParserImplTest : ShouldSpec({
|
|||||||
val cedictFilePath = "/cedict_1_0_ts_utf-8_mdbg.txt.gz"
|
val cedictFilePath = "/cedict_1_0_ts_utf-8_mdbg.txt.gz"
|
||||||
val cedictFileStream = GZIPInputStream(javaClass.getResourceAsStream(cedictFilePath))
|
val cedictFileStream = GZIPInputStream(javaClass.getResourceAsStream(cedictFilePath))
|
||||||
|
|
||||||
val cedictParser = CedictParserImpl()
|
val cedictParser = RegexCedictParser()
|
||||||
val cedictEntries = cedictParser.parseCedict(cedictFileStream)
|
val cedictEntries = cedictParser.parseCedict(cedictFileStream)
|
||||||
|
|
||||||
cedictEntries.toList().size shouldBe 122_508
|
cedictEntries.toList().size shouldBe 122_508
|
||||||
|
Loading…
Reference in New Issue
Block a user