Updating hex dump to better handle 7F/FF bytes for display. #54
This commit is contained in:
parent
f0c83d35fe
commit
a5714ed019
|
@ -43,12 +43,6 @@ public class AppleUtil {
|
||||||
*/
|
*/
|
||||||
private static final int BYTES_PER_LINE = 16;
|
private static final int BYTES_PER_LINE = 16;
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the ASCII space character as used by the Apple ][.
|
|
||||||
* The high bit is off.
|
|
||||||
*/
|
|
||||||
private static final int APPLE_SPACE = 0x20;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bit masks used for the bit shifting or testing operations.
|
* Bit masks used for the bit shifting or testing operations.
|
||||||
*/
|
*/
|
||||||
|
@ -582,11 +576,11 @@ public class AppleUtil {
|
||||||
int index = offset+a;
|
int index = offset+a;
|
||||||
if (index < bytes.length) {
|
if (index < bytes.length) {
|
||||||
char ch = (char) (bytes[index] & 0x7f);
|
char ch = (char) (bytes[index] & 0x7f);
|
||||||
if ((byte)ch >= (byte)APPLE_SPACE) {
|
if (Character.isISOControl(ch)) {
|
||||||
printer.print(ch);
|
printer.print('.');
|
||||||
} else {
|
} else {
|
||||||
printer.print('.');
|
printer.print(ch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printer.print(' ');
|
printer.print(' ');
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package com.webcodepro.applecommander.util;
|
package com.webcodepro.applecommander.util;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@ -113,4 +114,26 @@ public class AppleUtilTest {
|
||||||
// Confirm that these disks are identical:
|
// Confirm that these disks are identical:
|
||||||
assertTrue(AppleUtil.disksEqualByBlock(prodosDiskDosOrder, prodosDiskNibbleOrder));
|
assertTrue(AppleUtil.disksEqualByBlock(prodosDiskDosOrder, prodosDiskNibbleOrder));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetHexDump_expectedWidth() {
|
||||||
|
final int expectedWidth = 76;
|
||||||
|
|
||||||
|
// Setup an array of all byte values
|
||||||
|
byte[] data = new byte[256];
|
||||||
|
for (int i=0; i<data.length; i++) {
|
||||||
|
data[i] = (byte)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the width is expected and there are no control characters
|
||||||
|
String result = AppleUtil.getHexDump(data);
|
||||||
|
String[] lines = result.split("\n");
|
||||||
|
for (String line : lines) {
|
||||||
|
System.out.println(line);
|
||||||
|
if (line.startsWith("$")) {
|
||||||
|
assertEquals(expectedWidth, line.length());
|
||||||
|
line.chars().forEach(i -> assertTrue(Integer.toString(i), i >= ' '));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue