Moved ranged safe reads in block scanner

This commit is contained in:
Willem Cazander 2025-01-16 14:22:08 +01:00
parent 79d8b977a6
commit 619f01906f

View file

@ -152,6 +152,18 @@ public class FourCornerZionStenoLexer {
} }
abstract ScanResult process(Iterator<Integer> input); abstract ScanResult process(Iterator<Integer> input);
protected ScanResult safeReadCakePoints(Iterator<Integer> input, List<Integer> result) {
return safeReadRange(input, result, false);
}
protected ScanResult safeReadSliceOffsets(Iterator<Integer> input, List<Integer> result) {
return safeReadRange(input, result, true);
}
protected ScanResult safeReadRange(Iterator<Integer> input, List<Integer> result, boolean offset) {
return safeReadRanged(input, blockStart, blockStop, result, offset);
}
} }
public void read(List<Integer> points) { public void read(List<Integer> points) {
@ -214,15 +226,7 @@ public class FourCornerZionStenoLexer {
return ScanResult.DONE; return ScanResult.DONE;
} }
private ScanResult safeReadCakePoints(Iterator<Integer> input, int start, int stop, List<Integer> result) { private ScanResult safeReadRanged(Iterator<Integer> input, int start, int stop, List<Integer> result, boolean offset) {
return safeReadRange(input, start, stop, result, false);
}
private ScanResult safeReadSliceOffsets(Iterator<Integer> input, int start, int stop, List<Integer> result) {
return safeReadRange(input, start, stop, result, true);
}
private ScanResult safeReadRange(Iterator<Integer> input, int start, int stop, List<Integer> result, boolean offset) {
while (cakePoint >= start && cakePoint <= stop) { while (cakePoint >= start && cakePoint <= stop) {
if (offset) { if (offset) {
result.add(cakePoint - start); result.add(cakePoint - start);
@ -248,7 +252,7 @@ public class FourCornerZionStenoLexer {
@Override @Override
public ScanResult process(Iterator<Integer> input) { public ScanResult process(Iterator<Integer> input) {
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
ScanResult status = safeReadSliceOffsets(input, cakeSlice.getStart(), cakeSlice.getStop(), result); ScanResult status = safeReadSliceOffsets(input, result);
if (!result.isEmpty()) { if (!result.isEmpty()) {
handler.strobeWords(cakeSlice, result); handler.strobeWords(cakeSlice, result);
} }
@ -265,7 +269,7 @@ public class FourCornerZionStenoLexer {
@Override @Override
public ScanResult process(Iterator<Integer> input) { public ScanResult process(Iterator<Integer> input) {
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
ScanResult status = safeReadCakePoints(input, FourCornerDotCake.FC_NETHER.getStart(), FourCornerDotCake.FC_NETHER.getStop(), result); ScanResult status = safeReadCakePoints(input, result);
if (!result.isEmpty()) { if (!result.isEmpty()) {
handlePoints(result); handlePoints(result);
} }
@ -287,7 +291,7 @@ public class FourCornerZionStenoLexer {
@Override @Override
public ScanResult process(Iterator<Integer> input) { public ScanResult process(Iterator<Integer> input) {
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
ScanResult status = safeReadCakePoints(input, FourCornerDotCake.FC_NCR1632_XD.getStart(), FourCornerDotCake.FC_NCR1632_XN.getStop(), result); ScanResult status = safeReadCakePoints(input, result);
if (!result.isEmpty()) { if (!result.isEmpty()) {
handlePoints(result); // mix of the two blocks handlePoints(result); // mix of the two blocks
} }
@ -342,7 +346,7 @@ public class FourCornerZionStenoLexer {
@Override @Override
public ScanResult process(Iterator<Integer> input) { public ScanResult process(Iterator<Integer> input) {
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
ScanResult status = safeReadCakePoints(input, FourCornerDotCake.FC_UNI2K_11.getStart(), FourCornerDotCake.FC_UNI2K_22.getStop(), result); ScanResult status = safeReadCakePoints(input, result);
if (!result.isEmpty()) { if (!result.isEmpty()) {
handlePoints(result); // mix of the two unicode blocks pages handlePoints(result); // mix of the two unicode blocks pages
} }
@ -386,7 +390,7 @@ public class FourCornerZionStenoLexer {
@Override @Override
public ScanResult process(Iterator<Integer> input) { public ScanResult process(Iterator<Integer> input) {
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
ScanResult status = safeReadCakePoints(input, FourCornerDotCake.FC_CDC1604_P6.getStart(), FourCornerDotCake.__MIND_THE_GAP8.getStop(), result); ScanResult status = safeReadCakePoints(input, result);
if (!result.isEmpty()) { if (!result.isEmpty()) {
handlePoints(result); handlePoints(result);
} }