From d54f47c0a2e18470fe5f3d1491f93aa469705d90 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 25 Jul 1999 08:08:22 +0000 Subject: [PATCH] optimized checkTypeSig git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1128 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/bytecode/TypeSignature.java | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/jode/jode/bytecode/TypeSignature.java b/jode/jode/bytecode/TypeSignature.java index d5ccf81..e7c3d41 100644 --- a/jode/jode/bytecode/TypeSignature.java +++ b/jode/jode/bytecode/TypeSignature.java @@ -204,18 +204,21 @@ public class TypeSignature { return methodTypeSig.substring(methodTypeSig.lastIndexOf(')')+1); } - private static void checkClassName(String clName) - throws IllegalArgumentException + /** + * Check if there is a valid class name starting at index + * in string typesig and ending with a semicolon. + * @return the index at which the class name ends. + * @exception IllegalArgumentException if there was an illegal character. + * @exception StringIndexOutOfBoundsException if the typesig ended early. + */ + private static int checkClassName(String clName, int i) + throws IllegalArgumentException, StringIndexOutOfBoundsException { - boolean start = true; - for (int i=0; i< clName.length(); i++) { - char c = clName.charAt(i); - if (c == '/') - start = true; - else if (start && Character.isJavaIdentifierStart(c)) - start = false; - else if ((start && false /*XXX*/) - || !Character.isJavaIdentifierPart(c)) + while (true) { + char c = clName.charAt(i++); + if (c == ';') + return i; + if (c != '/' && !Character.isJavaIdentifierPart(c)) throw new IllegalArgumentException("Illegal java class name: " + clName); } @@ -233,10 +236,7 @@ public class TypeSignature { while (c == '[') c = typesig.charAt(index++); if (c == 'L') { - int end = typesig.indexOf(';', index); - // next instruction throws StringIndexOutOfBounds, if no ; exists. - checkClassName(typesig.substring(index+1, end)); - index = end + 1; + index = checkClassName(typesig, index); } else { if ("ZBSCIJFD".indexOf(c) == -1) throw new IllegalArgumentException("Type sig error: "+typesig);