From dd14f34f26454add980f33fcf7e6978f911ab61f Mon Sep 17 00:00:00 2001 From: winfriedgerlach <158032591+winfriedgerlach@users.noreply.github.com> Date: Fri, 22 Nov 2024 21:40:04 +0100 Subject: [PATCH] #216 Cleanup: unused private static arrays in WstxInputData and StreamScanner (#217) --- .../java/com/ctc/wstx/io/WstxInputData.java | 93 ------------------- .../java/com/ctc/wstx/sr/StreamScanner.java | 54 ++--------- 2 files changed, 8 insertions(+), 139 deletions(-) diff --git a/src/main/java/com/ctc/wstx/io/WstxInputData.java b/src/main/java/com/ctc/wstx/io/WstxInputData.java index 928c4835..cc5bf026 100644 --- a/src/main/java/com/ctc/wstx/io/WstxInputData.java +++ b/src/main/java/com/ctc/wstx/io/WstxInputData.java @@ -50,99 +50,6 @@ public class WstxInputData */ public final static int MAX_UNICODE_CHAR = 0x10FFFF; - /* - //////////////////////////////////////////////////// - // Character validity constants, structs - //////////////////////////////////////////////////// - */ - - /** - * We will only use validity array for first 256 characters, mostly - * because after those characters it's easier to do fairly simple - * block checks. - */ - private final static int VALID_CHAR_COUNT = 0x100; - - // These are the same for both 1.0 and 1.1... -// private final static int FIRST_VALID_FOR_FIRST = 0x0041; // 'A' -// private final static int FIRST_VALID_FOR_REST = 0x002D; // '.' - - private final static byte NAME_CHAR_INVALID_B = (byte) 0; - private final static byte NAME_CHAR_ALL_VALID_B = (byte) 1; - private final static byte NAME_CHAR_VALID_NONFIRST_B = (byte) -1; - - private final static byte[] sCharValidity = new byte[VALID_CHAR_COUNT]; - - static { - /* First, since all valid-as-first chars are also valid-as-other chars, - * we'll initialize common chars: - */ - sCharValidity['_'] = NAME_CHAR_ALL_VALID_B; - for (int i = 0, last = ('z' - 'a'); i <= last; ++i) { - sCharValidity['A' + i] = NAME_CHAR_ALL_VALID_B; - sCharValidity['a' + i] = NAME_CHAR_ALL_VALID_B; - } - // not all are fully valid, but - for (int i = 0xC0; i < VALID_CHAR_COUNT; ++i) { - sCharValidity[i] = NAME_CHAR_ALL_VALID_B; - } - // ... now we can 'revert' ones not fully valid: - sCharValidity[0xD7] = NAME_CHAR_INVALID_B; - sCharValidity[0xF7] = NAME_CHAR_INVALID_B; - - /* And then we can proceed with ones only valid-as-other. - */ - sCharValidity['-'] = NAME_CHAR_VALID_NONFIRST_B; - sCharValidity['.'] = NAME_CHAR_VALID_NONFIRST_B; - sCharValidity[0xB7] = NAME_CHAR_VALID_NONFIRST_B; - for (int i = '0'; i <= '9'; ++i) { - sCharValidity[i] = NAME_CHAR_VALID_NONFIRST_B; - } - } - - /** - * Public identifiers only use 7-bit ascii range. - */ - private final static int VALID_PUBID_CHAR_COUNT = 0x80; - private final static byte[] sPubidValidity = new byte[VALID_PUBID_CHAR_COUNT]; -// private final static byte PUBID_CHAR_INVALID_B = (byte) 0; - private final static byte PUBID_CHAR_VALID_B = (byte) 1; - static { - for (int i = 0, last = ('z' - 'a'); i <= last; ++i) { - sPubidValidity['A' + i] = PUBID_CHAR_VALID_B; - sPubidValidity['a' + i] = PUBID_CHAR_VALID_B; - } - for (int i = '0'; i <= '9'; ++i) { - sPubidValidity[i] = PUBID_CHAR_VALID_B; - } - - // 3 main white space types are valid - sPubidValidity[0x0A] = PUBID_CHAR_VALID_B; - sPubidValidity[0x0D] = PUBID_CHAR_VALID_B; - sPubidValidity[0x20] = PUBID_CHAR_VALID_B; - - // And many of punctuation/separator ascii chars too: - sPubidValidity['-'] = PUBID_CHAR_VALID_B; - sPubidValidity['\''] = PUBID_CHAR_VALID_B; - sPubidValidity['('] = PUBID_CHAR_VALID_B; - sPubidValidity[')'] = PUBID_CHAR_VALID_B; - sPubidValidity['+'] = PUBID_CHAR_VALID_B; - sPubidValidity[','] = PUBID_CHAR_VALID_B; - sPubidValidity['.'] = PUBID_CHAR_VALID_B; - sPubidValidity['/'] = PUBID_CHAR_VALID_B; - sPubidValidity[':'] = PUBID_CHAR_VALID_B; - sPubidValidity['='] = PUBID_CHAR_VALID_B; - sPubidValidity['?'] = PUBID_CHAR_VALID_B; - sPubidValidity[';'] = PUBID_CHAR_VALID_B; - sPubidValidity['!'] = PUBID_CHAR_VALID_B; - sPubidValidity['*'] = PUBID_CHAR_VALID_B; - sPubidValidity['#'] = PUBID_CHAR_VALID_B; - sPubidValidity['@'] = PUBID_CHAR_VALID_B; - sPubidValidity['$'] = PUBID_CHAR_VALID_B; - sPubidValidity['_'] = PUBID_CHAR_VALID_B; - sPubidValidity['%'] = PUBID_CHAR_VALID_B; - } - /* //////////////////////////////////////////////////// // Configuration diff --git a/src/main/java/com/ctc/wstx/sr/StreamScanner.java b/src/main/java/com/ctc/wstx/sr/StreamScanner.java index 7ca155f2..789c2e37 100644 --- a/src/main/java/com/ctc/wstx/sr/StreamScanner.java +++ b/src/main/java/com/ctc/wstx/sr/StreamScanner.java @@ -92,49 +92,11 @@ public abstract class StreamScanner /////////////////////////////////////////////////////////////////////// */ - /** - * We will only use validity array for first 256 characters, mostly - * because after those characters it's easier to do fairly simple - * block checks. - */ - private final static int VALID_CHAR_COUNT = 0x100; - - private final static byte NAME_CHAR_INVALID_B = (byte) 0; - private final static byte NAME_CHAR_ALL_VALID_B = (byte) 1; - private final static byte NAME_CHAR_VALID_NONFIRST_B = (byte) -1; - - private final static byte[] sCharValidity = new byte[VALID_CHAR_COUNT]; - - static { - // First, since all valid-as-first chars are also valid-as-other chars, - // we'll initialize common chars: - sCharValidity['_'] = NAME_CHAR_ALL_VALID_B; - for (int i = 0, last = ('z' - 'a'); i <= last; ++i) { - sCharValidity['A' + i] = NAME_CHAR_ALL_VALID_B; - sCharValidity['a' + i] = NAME_CHAR_ALL_VALID_B; - } - for (int i = 0xC0; i < 0xF6; ++i) { // not all are fully valid, but - sCharValidity[i] = NAME_CHAR_ALL_VALID_B; - } - // ... now we can 'revert' ones not fully valid: - sCharValidity[0xD7] = NAME_CHAR_INVALID_B; - sCharValidity[0xF7] = NAME_CHAR_INVALID_B; - - // And then we can proceed with ones only valid-as-other. - sCharValidity['-'] = NAME_CHAR_VALID_NONFIRST_B; - sCharValidity['.'] = NAME_CHAR_VALID_NONFIRST_B; - sCharValidity[0xB7] = NAME_CHAR_VALID_NONFIRST_B; - for (int i = '0'; i <= '9'; ++i) { - sCharValidity[i] = NAME_CHAR_VALID_NONFIRST_B; - } - } - /** * Public identifiers only use 7-bit ascii range. */ private final static int VALID_PUBID_CHAR_COUNT = 0x80; private final static byte[] sPubidValidity = new byte[VALID_PUBID_CHAR_COUNT]; -// private final static byte PUBID_CHAR_INVALID_B = (byte) 0; private final static byte PUBID_CHAR_VALID_B = (byte) 1; static { for (int i = 0, last = ('z' - 'a'); i <= last; ++i) { @@ -401,7 +363,7 @@ protected StreamScanner(WstxInputSource input, ReaderConfig cfg, mCfgTreatCharRefsAsEntities = mConfig.willTreatCharRefsAsEnts(); if (mCfgTreatCharRefsAsEntities) { - mCachedEntities = new HashMap(); + mCachedEntities = new HashMap<>(); } else { mCachedEntities = Collections.emptyMap(); } @@ -500,7 +462,7 @@ public void throwParseError(String format, Object arg, Object arg2) throws XMLStreamException { String msg = (arg == null && arg2 == null) ? format - : MessageFormat.format(format, new Object[] { arg, arg2 }); + : MessageFormat.format(format, arg, arg2); throw constructWfcException(msg); } @@ -510,7 +472,7 @@ public void reportProblem(String probType, String format, Object arg, Object arg XMLReporter rep = mConfig.getXMLReporter(); if (rep != null) { _reportProblem(rep, probType, - MessageFormat.format(format, new Object[] { arg, arg2 }), null); + MessageFormat.format(format, arg, arg2), null); } } @@ -522,7 +484,7 @@ public void reportProblem(Location loc, String probType, XMLReporter rep = mConfig.getXMLReporter(); if (rep != null) { String msg = (arg != null || arg2 != null) ? - MessageFormat.format(format, new Object[] { arg, arg2 }) : format; + MessageFormat.format(format, arg, arg2) : format; _reportProblem(rep, probType, msg, loc); } } @@ -620,7 +582,7 @@ public void reportValidationProblem(Location loc, String msg) public void reportValidationProblem(String format, Object arg, Object arg2) throws XMLStreamException { - reportValidationProblem(MessageFormat.format(format, new Object[] { arg, arg2 })); + reportValidationProblem(MessageFormat.format(format, arg, arg2)); } /* @@ -1520,7 +1482,7 @@ protected int fullyResolveEntity(boolean allowExt) char c = getNextCharFromCurrent(SUFFIX_IN_ENTITY_REF); // Do we have a (numeric) character entity reference? if (c == '#') { // numeric - final StringBuffer originalSurface = new StringBuffer("#"); + final StringBuilder originalSurface = new StringBuilder("#"); int ch = resolveCharEnt(originalSurface, true); if (mCfgTreatCharRefsAsEntities) { final char[] originalChars = new char[originalSurface.length()]; @@ -1590,7 +1552,7 @@ protected EntityDecl getIntEntity(int ch, final char[] originalChars) if (ch <= 0xFFFF) { repl = Character.toString((char) ch); } else { - StringBuffer sb = new StringBuffer(2); + StringBuilder sb = new StringBuilder(2); ch -= 0x10000; sb.append((char) ((ch >> 10) + 0xD800)); sb.append((char) ((ch & 0x3FF) + 0xDC00)); @@ -2317,7 +2279,7 @@ protected final void parseUntil(TextBuffer tb, char endChar, boolean convertLFs, /////////////////////////////////////////////////////////////////////// */ - private int resolveCharEnt(StringBuffer originalCharacters, boolean validateChar) + private int resolveCharEnt(StringBuilder originalCharacters, boolean validateChar) throws XMLStreamException { int value = 0;