From a2746b6323ccfc0867e148d92865a9b3f3eea4f4 Mon Sep 17 00:00:00 2001 From: Willem Date: Tue, 24 Dec 2024 00:33:52 +0100 Subject: [PATCH] Added terminator out of range end number mode --- .../src/main/java/org/x4o/o2o/CDC1604DashP6.java | 12 ++++++------ .../test/java/org/x4o/o2o/CDC1604DashP6Test.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/CDC1604DashP6.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/CDC1604DashP6.java index 8b70aba..da142c6 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/CDC1604DashP6.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/CDC1604DashP6.java @@ -219,6 +219,12 @@ public enum CDC1604DashP6 { CDC1604DashP6 numberMode = null; while (cdc.hasNext()) { 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)) { continue; } @@ -229,12 +235,6 @@ public enum CDC1604DashP6 { numberMode = cdc.next(); continue; } - - if (numberMode != null) { - if (cdcPoint.ordinal() < CDC1604DashP6._A.ordinal()) { - numberMode = null; - } - } if (numberMode == null) { buf.appendCodePoint(cdcPoint.asciiByte()); } else { diff --git a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/CDC1604DashP6Test.java b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/CDC1604DashP6Test.java index ddbc8e5..e87751d 100644 --- a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/CDC1604DashP6Test.java +++ b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/CDC1604DashP6Test.java @@ -22,6 +22,7 @@ */ package org.x4o.o2o; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -97,4 +98,18 @@ public class CDC1604DashP6Test { String out = CDC1604DashP6.convertToUnicode(cdc); Assertions.assertEquals("01201337", out); } + + public void testNumberPieOutOfRange() throws Exception { + List 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); + } }