mirror of
https://github.com/KarolS/millfork.git
synced 2025-08-09 10:24:57 +00:00
Don't repeat warnings about identical replaced characters in the lenient mode
This commit is contained in:
@@ -8,6 +8,8 @@ import millfork.{CompilationFlag, CompilationOptions}
|
|||||||
import millfork.error.{ConsoleLogger, Logger}
|
import millfork.error.{ConsoleLogger, Logger}
|
||||||
import millfork.node.Position
|
import millfork.node.Position
|
||||||
|
|
||||||
|
import scala.collection.mutable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karol Stasiak
|
* @author Karol Stasiak
|
||||||
*/
|
*/
|
||||||
@@ -140,6 +142,8 @@ class TableTextCodec(override val name: String,
|
|||||||
val directDecompositions: Map[Char, List[Int]],
|
val directDecompositions: Map[Char, List[Int]],
|
||||||
val escapeSequences: Map[String, List[Int]]) extends TextCodec {
|
val escapeSequences: Map[String, List[Int]]) extends TextCodec {
|
||||||
|
|
||||||
|
private val alreadyWarned = mutable.Set[Char]()
|
||||||
|
|
||||||
override val stringTerminator: List[Int] = List(stringTerminatorChar)
|
override val stringTerminator: List[Int] = List(stringTerminatorChar)
|
||||||
|
|
||||||
private def isPrintable(c: Int) = {
|
private def isPrintable(c: Int) = {
|
||||||
@@ -200,8 +204,9 @@ class TableTextCodec(override val name: String,
|
|||||||
Some(List(index))
|
Some(List(index))
|
||||||
} else if (lenient) {
|
} else if (lenient) {
|
||||||
val alternative = TextCodec.lossyAlternatives.getOrElse(c, Nil).:+("?").find(alts => alts.forall(alt => encodeChar(log, position, alt, options, lenient = false).isDefined)).getOrElse("")
|
val alternative = TextCodec.lossyAlternatives.getOrElse(c, Nil).:+("?").find(alts => alts.forall(alt => encodeChar(log, position, alt, options, lenient = false).isDefined)).getOrElse("")
|
||||||
if (options.flag(CompilationFlag.FallbackValueUseWarning)) {
|
if (options.flag(CompilationFlag.FallbackValueUseWarning) && !alreadyWarned(c)) {
|
||||||
log.warn(s"Cannot encode ${format(c)} in encoding `$name`, replaced it with ${format(alternative)}", position)
|
log.warn(s"Cannot encode ${format(c)} in encoding `$name`, replaced it with ${format(alternative)}", position)
|
||||||
|
alreadyWarned += c
|
||||||
}
|
}
|
||||||
Some(alternative.toList.flatMap(encodeChar(log, position, _, options, lenient = false).get))
|
Some(alternative.toList.flatMap(encodeChar(log, position, _, options, lenient = false).get))
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user