From 73d408f1ec75a9751e71f597a6a446f9bb2955bc Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 17 Jan 2025 00:53:21 +0100 Subject: [PATCH] Added single word strobe to FC18 lexer candlelier --- .../x4o/fc18/FourCornerUnicodeDisplay.java | 75 +++++++++---------- .../fc18/zion7/FourCornerZion7Candlelier.java | 6 ++ .../fc18/zion7/FourCornerZionStenoLexer.java | 20 ++--- 3 files changed, 53 insertions(+), 48 deletions(-) diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java index 9ac2d9c..1a1ee91 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java @@ -135,9 +135,12 @@ public class FourCornerUnicodeDisplay { private final class StenoUnicodePrinter implements FourCornerZion7Candlelier, FourCornerZionStenoLexerSmoke.Adapter { private final StringBuilder output; + private final FourCornerZionStenoLexer thisDisplayEscaked; + private boolean wasExternalWord = false; private StenoUnicodePrinter(StringBuilder output) { this.output = Objects.requireNonNull(output); + this.thisDisplayEscaked = new FourCornerZionStenoLexer(this, true); } private boolean printedEscape(FourCornerDotCake slice, int offset) { @@ -164,61 +167,58 @@ public class FourCornerUnicodeDisplay { @Override public void strobeWords(FourCornerDotCake slice, List offsets) { + for (int i = 0; i < offsets.size(); i++) { + strobeWord(slice, offsets.get(i)); + } + } + + @Override + public void strobeWord(FourCornerDotCake slice, int offset) { + if (printedEscape(slice, offset)) { + return; + } FourCornerX00PetitVidePoints[] videPoints = slice.getVidePoints(); if (slice.isExternWord()) { String fcQName = slice.qname(); - Iterator i = offsets.iterator(); - while (i.hasNext()) { - Integer offset = i.next(); - if (printedEscape(slice, offset)) { - continue; - } - String key = fcQName + "." + Integer.toString(offset); - String value = null; - if (value != null) { - output.append(value); - } else { - FourCornerX00PetitVidePoints videPoint = videPoints[offset]; - if (videPoint instanceof FourCornerX18CakeWord) { - FourCornerX18CakeWord cakeWord = FourCornerX18CakeWord.class.cast(videPoint); - FourCornerX18CakePoints[] wordDefault = cakeWord.nameDefault(); - for (FourCornerX18CakePoints letter : wordDefault) { - if (letter.isX21()) { - Arrays.stream(letter.toX21().codePoints()).forEach(v -> output.appendCodePoint(v)); - } + String key = fcQName + "." + Integer.toString(offset); + String value = null; + if (value != null) { + output.append(value); + } else { + FourCornerX00PetitVidePoints videPoint = videPoints[offset]; + if (videPoint instanceof FourCornerX18CakeWord) { + FourCornerX18CakeWord cakeWord = FourCornerX18CakeWord.class.cast(videPoint); + FourCornerX18CakePoints[] wordDefault = cakeWord.nameDefault(); + for (FourCornerX18CakePoints letter : wordDefault) { + if (letter.isX21()) { + Arrays.stream(letter.toX21().codePoints()).forEach(v -> output.appendCodePoint(v)); } } } - if (renderSeperator != null && i.hasNext()) { - output.append(renderSeperator); - } } + if (renderSeperator != null && wasExternalWord) { + output.append(renderSeperator); + } + wasExternalWord = true; return; } + wasExternalWord = false; if (videPoints.length > 0) { - for (Integer offset : offsets) { - if (printedEscape(slice, offset)) { - continue; - } - //if (offset < 0 || offset > videPoints.length) { - // continue; - //} - FourCornerX00PetitVidePoints videPoint = videPoints[offset]; - if (videPoint.isX21()) { - Arrays.stream(videPoint.toX21().codePoints()).forEach(v -> output.appendCodePoint(v)); - } + //if (offset < 0 || offset > videPoints.length) { + // continue; + //} + FourCornerX00PetitVidePoints videPoint = videPoints[offset]; + if (videPoint.isX21()) { + Arrays.stream(videPoint.toX21().codePoints()).forEach(v -> output.appendCodePoint(v)); } return; } output.append(slice.name()); output.append("#"); - for (Integer offset : offsets) { - output.append(offset); - output.append("-"); - } + output.append(offset); output.append("#"); } @@ -246,7 +246,6 @@ public class FourCornerUnicodeDisplay { @Override public void strobeRecursiveCake(List cakePoints) { - FourCornerZionStenoLexer thisDisplayEscaked = new FourCornerZionStenoLexer(this, true); thisDisplayEscaked.read(cakePoints); } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java index dd839eb..8a30c61 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java @@ -36,6 +36,8 @@ public interface FourCornerZion7Candlelier { /// Block of relative slice numbers. void strobeWords(FourCornerDotCake slice, List offsets); + void strobeWord(FourCornerDotCake slice, int offset); + /// One based already void strobeNCR1632(BigInteger denominator, BigInteger numerator); @@ -51,6 +53,10 @@ public interface FourCornerZion7Candlelier { default void strobeWords(FourCornerDotCake slice, List offsets) { } + @Override + default void strobeWord(FourCornerDotCake slice, int offset) { + } + @Override default void strobeNCR1632(BigInteger denominator, BigInteger numerator) { } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java index 912e293..0a50bf4 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java @@ -399,9 +399,9 @@ public class FourCornerZionStenoLexer { // No escaping, print CDC or DEC code if (!lexer.handlerEscape) { if (FourCornerDotCake.FC_DEC0127_PX0.contains(cdcDECPoint)) { - lexer.handler.strobeWords(FourCornerDotCake.FC_DEC0127_PX0, List.of(cdcDECPoint - FourCornerDotCake.FC_DEC0127_PX0.getStart())); + lexer.handler.strobeWord(FourCornerDotCake.FC_DEC0127_PX0, cdcDECPoint - FourCornerDotCake.FC_DEC0127_PX0.getStart()); } else { - lexer.handler.strobeWords(FourCornerDotCake.FC_CDC1604_P6, List.of(cdcDECPoint)); + lexer.handler.strobeWord(FourCornerDotCake.FC_CDC1604_P6, cdcDECPoint); } continue; } @@ -498,27 +498,27 @@ public class FourCornerZionStenoLexer { // FIXME: this pages need a stop on out of range too if (decMode == FCDotDEC0127DashPX0.ESC6_APL0127_P7A) { - lexer.handler.strobeWords(FourCornerDotCake.FC_APL0127_P7A, List.of(cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal())); + lexer.handler.strobeWord(FourCornerDotCake.FC_APL0127_P7A, cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal()); return; } if (decMode == FCDotDEC0127DashPX0.ESC6_APL0127_P7B) { - lexer.handler.strobeWords(FourCornerDotCake.FC_APL0127_P7B, List.of(cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal())); + lexer.handler.strobeWord(FourCornerDotCake.FC_APL0127_P7B, cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal()); return; } if (decMode == FCDotDEC0127DashPX0.ESC6_APL0127_P7C) { - lexer.handler.strobeWords(FourCornerDotCake.FC_APL0127_P7C, List.of(cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal())); + lexer.handler.strobeWord(FourCornerDotCake.FC_APL0127_P7C, cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal()); return; } if (decMode == FCDotDEC0127DashPX0.ESC6_BYD0127_P7D) { - lexer.handler.strobeWords(FourCornerDotCake.FC_BYD0127_P7D, List.of(cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal())); + lexer.handler.strobeWord(FourCornerDotCake.FC_BYD0127_P7D, cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal()); return; } if (decMode == FCDotDEC0127DashPX0.ESC6_BYD0127_P7E) { - lexer.handler.strobeWords(FourCornerDotCake.FC_BYD0127_P7E, List.of(cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal())); + lexer.handler.strobeWord(FourCornerDotCake.FC_BYD0127_P7E, cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal()); return; } if (decMode == FCDotDEC0127DashPX0.ESC6_BYD0127_P7F) { - lexer.handler.strobeWords(FourCornerDotCake.FC_BYD0127_P7F, List.of(cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal())); + lexer.handler.strobeWord(FourCornerDotCake.FC_BYD0127_P7F, cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal()); return; } @@ -540,14 +540,14 @@ public class FourCornerZionStenoLexer { lexer.smokeSignals.burnUnsupported(lexer.currLine, lexer.currCol, cdcPoint); return; } - lexer.handler.strobeWords(slice.get(), List.of(cdcPoint)); + lexer.handler.strobeWord(slice.get(), cdcPoint); return; } if (numberPIE) { int terminatorOffZero = numberMode - FCDotCDC1604DashP6.NX01_A.ordinal(); int numberIdxOffZero = cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal(); FourCornerDotCake slice = FourCornerDotCake.values()[terminatorOffZero + FourCornerDotCake.FC_PIE9C_01.ordinal()]; - lexer.handler.strobeWords(slice, List.of(numberIdxOffZero)); + lexer.handler.strobeWord(slice, numberIdxOffZero); } else { // _PIN = ²⁄₁₂ int terminatorOff = numberMode - FCDotCDC1604DashP6.NX01_A.ordinal() + 1; int numberIdxOff = cdcPoint - FCDotCDC1604DashP6.NX01_A.ordinal() + 1;