Skip to content

Commit

Permalink
Renamed LazyList to Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jan 24, 2025
1 parent c7c8705 commit f2af6d2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/core/hieroglyph.CharDecoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ extends Decodable:

def decode(bytes: Bytes, omit: Boolean): Text =
val buf: StringBuilder = StringBuilder()
decode(LazyList(bytes)).each { text => buf.append(text.s) }
decode(Stream(bytes)).each { text => buf.append(text.s) }
buf.toString.tt

def decode(bytes: Bytes): Text = decode(bytes, false)

def decode(stream: LazyList[Bytes]): LazyList[Text] =
def decode(stream: Stream[Bytes]): Stream[Text] =
val decoder = encoding.charset.newDecoder().nn
val out = jn.CharBuffer.allocate(4096).nn
val in = jn.ByteBuffer.allocate(4096).nn

def recur(todo: LazyList[Array[Byte]], offset: Int = 0, total: Int = 0): LazyList[Text] =
def recur(todo: Stream[Array[Byte]], offset: Int = 0, total: Int = 0): Stream[Text] =
val count = in.remaining

if !todo.isEmpty then in.put(todo.head, offset, in.remaining.min(todo.head.length - offset))
Expand All @@ -72,7 +72,7 @@ extends Decodable:
out.clear()

def continue =
if todo.isEmpty && !status.isOverflow then LazyList()
if todo.isEmpty && !status.isOverflow then Stream()
else if !todo.isEmpty && count >= todo.head.length - offset
then recur(todo.tail, 0, total + todo.head.length - offset)
else recur(todo, offset + count, total + count)
Expand Down
2 changes: 1 addition & 1 deletion src/core/hieroglyph.CharEncoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ extends Encodable:
type Self = Text
type Format = Bytes
def encode(text: Text): Bytes = text.s.getBytes(encoding.name.s).nn.immutable(using Unsafe)
def encode(stream: LazyList[Text]): LazyList[Bytes] = stream.map(encode)
def encode(stream: Stream[Text]): Stream[Bytes] = stream.map(encode)
4 changes: 2 additions & 2 deletions src/core/hieroglyph.Unicode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object Unicode:
else map.updated(range, width)

@tailrec
def recur(stream: LazyList[Text], map: TreeMap[CharRange, EaWidth]): TreeMap[CharRange, EaWidth] =
def recur(stream: Stream[Text], map: TreeMap[CharRange, EaWidth]): TreeMap[CharRange, EaWidth] =
stream match
case r"${Hex(from)}([0-9A-F]{4})\.\.${Hex(to)}([0-9A-F]{4});${EaWidth(w)}([AFHNW]a?).*" #:: tail =>
recur(tail, map.append(CharRange(from, to), w))
Expand All @@ -101,6 +101,6 @@ object Unicode:
Option(getClass.getResourceAsStream("/hieroglyph/EastAsianWidth.txt")).map(_.nn).getOrElse:
panic(m"could not find hieroglyph/EastAsianWidth.txt on the classpath")

val stream = scala.io.Source.fromInputStream(in).getLines.map(Text(_)).to(LazyList)
val stream = scala.io.Source.fromInputStream(in).getLines.map(Text(_)).to(Stream)

recur(stream, TreeMap())
2 changes: 1 addition & 1 deletion src/test/hieroglyph.Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object Tests extends Suite(t"Hieroglyph tests"):
for chunk <- 1 to 25 do
test(t"Decode Japanese text in chunks of size $chunk"):
import textSanitizers.skip
charDecoders.utf8.decode(japaneseBytes.grouped(chunk).to(LazyList)).join
charDecoders.utf8.decode(japaneseBytes.grouped(chunk).to(Stream)).join
.assert(_ == japanese)

val badUtf8 = Bytes(45, -62, 49, 48)
Expand Down

0 comments on commit f2af6d2

Please sign in to comment.