Skip to content

Commit

Permalink
make functions that mutate a StringBuilder private
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 23, 2023
1 parent 35fed01 commit e79ab47
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/scala/format/pgn/Pgn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ object PgnTree:
extension (tree: Tree[Move])
def isLong = tree.value.isLong || tree.variations.nonEmpty

def render(builder: StringBuilder): Unit =
private[pgn] def render(builder: StringBuilder): Unit =
render(builder, !tree.value.ply.turn.black)

@annotation.tailrec
def render(builder: StringBuilder, dot: Boolean): Unit =
private def render(builder: StringBuilder, dot: Boolean): Unit =
if tree.isVariation then builder.append(Move.render(tree.value.variationComments))
val d = tree.prefix(dot, builder)
renderValueAndVariations(builder)
Expand All @@ -54,15 +54,15 @@ object PgnTree:
builder.addOne(' ')
x.render(builder, d)

def prefix(dot: Boolean, builder: StringBuilder): Boolean =
private def prefix(dot: Boolean, builder: StringBuilder): Boolean =
if tree.value.ply.turn.black then
builder.append(tree.value.turnNumber).append(". ")
tree.isLong
else
if dot then builder.append(tree.value.turnNumber).append("... ")
false

def renderValueAndVariations(builder: StringBuilder) =
private def renderValueAndVariations(builder: StringBuilder) =
tree.value.render(builder)
tree.variations.foreach: x =>
builder.addOne(' ').addOne('(')
Expand Down Expand Up @@ -100,7 +100,6 @@ case class Move(
glyphs.toList.foreach:
case glyph if glyph.id <= 6 => builder.append(glyph.symbol)
case glyph => builder.append(" $").append(glyph.id)

if hasCommentsOrTime then
List(clockString, opening, result).flatten
.:::(comments.map(_ map Move.noDoubleLineBreak))
Expand Down

0 comments on commit e79ab47

Please sign in to comment.