Added terminator out of range end number mode

This commit is contained in:
Willem Cazander 2024-12-24 00:33:52 +01:00
parent 7dac9b0237
commit a2746b6323
2 changed files with 21 additions and 6 deletions

View file

@ -219,6 +219,12 @@ public enum CDC1604DashP6 {
CDC1604DashP6 numberMode = null; CDC1604DashP6 numberMode = null;
while (cdc.hasNext()) { while (cdc.hasNext()) {
CDC1604DashP6 cdcPoint = cdc.next(); CDC1604DashP6 cdcPoint = cdc.next();
if (numberMode != null && (cdcPoint.ordinal() > numberMode.ordinal())) {
numberMode = null; // out of range
}
if (numberMode != null && (cdcPoint.ordinal() < CDC1604DashP6._A.ordinal())) {
numberMode = null; // below index 1 is end number mode
}
if (_WORD_GLUE.equals(cdcPoint)) { if (_WORD_GLUE.equals(cdcPoint)) {
continue; continue;
} }
@ -229,12 +235,6 @@ public enum CDC1604DashP6 {
numberMode = cdc.next(); numberMode = cdc.next();
continue; continue;
} }
if (numberMode != null) {
if (cdcPoint.ordinal() < CDC1604DashP6._A.ordinal()) {
numberMode = null;
}
}
if (numberMode == null) { if (numberMode == null) {
buf.appendCodePoint(cdcPoint.asciiByte()); buf.appendCodePoint(cdcPoint.asciiByte());
} else { } else {

View file

@ -22,6 +22,7 @@
*/ */
package org.x4o.o2o; package org.x4o.o2o;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -97,4 +98,18 @@ public class CDC1604DashP6Test {
String out = CDC1604DashP6.convertToUnicode(cdc); String out = CDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("01201337", out); Assertions.assertEquals("01201337", out);
} }
public void testNumberPieOutOfRange() throws Exception {
List<CDC1604DashP6> cdc = new ArrayList<>();
cdc.add(CDC1604DashP6._WORD_NUMBER);
cdc.add(CDC1604DashP6._A);
cdc.add(CDC1604DashP6._B); // = B
cdc.add(CDC1604DashP6._WORD_NUMBER);
cdc.add(CDC1604DashP6._I);
cdc.add(CDC1604DashP6._C); // = 3
cdc.add(CDC1604DashP6._J); // = J
String out = CDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("B3J", out);
}
} }