Return Sequence instead of List #6
@ -1,12 +1,12 @@
|
||||
package com.marvinelsen.cedict.api
|
||||
|
||||
import com.marvinelsen.cedict.internal.CedictParserImpl
|
||||
import com.marvinelsen.cedict.internal.RegexCedictParser
|
||||
import java.io.InputStream
|
||||
|
||||
interface CedictParser {
|
||||
fun parseCedict(inputStream: InputStream): Sequence<CedictEntry>
|
||||
|
||||
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 java.io.InputStream
|
||||
|
||||
internal class CedictParserImpl : CedictParser {
|
||||
internal class RegexCedictParser : CedictParser {
|
||||
companion object {
|
||||
private const val DEFINITION_SEPARATOR = '/'
|
||||
private const val GLOSS_SEPARATOR = ';'
|
@ -9,7 +9,7 @@ import java.util.zip.GZIPInputStream
|
||||
|
||||
class CedictParserImplTest : ShouldSpec({
|
||||
should("parse lines correctly") {
|
||||
val cedictParser = CedictParserImpl()
|
||||
val cedictParser = RegexCedictParser()
|
||||
val cedictEntry =
|
||||
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 cedictFileStream = GZIPInputStream(javaClass.getResourceAsStream(cedictFilePath))
|
||||
|
||||
val cedictParser = CedictParserImpl()
|
||||
val cedictParser = RegexCedictParser()
|
||||
val cedictEntries = cedictParser.parseCedict(cedictFileStream)
|
||||
|
||||
cedictEntries.toList().size shouldBe 122_508
|
||||
|
Loading…
Reference in New Issue
Block a user