1 7 8 17 18 package jasmin; 19 20 abstract class ScannerUtils { 21 22 public static Number convertInt(String str, int radix) 27 throws NumberFormatException 28 { 29 boolean forceLong = false; 30 31 if(str.endsWith("L")) 32 { 33 forceLong = true; 34 str = str.substring(0, str.length() - 1); 35 } 36 37 long x = Long.parseLong(str, radix); 38 39 if (x <= (long)Integer.MAX_VALUE && x >= (long)Integer.MIN_VALUE && !forceLong) { 40 return new Integer ((int)x); 41 } 42 return new Long (x); 43 } 44 45 public static Number convertNumber(String str) 50 throws NumberFormatException 51 { 52 54 if (str.startsWith("0x")) { 55 return (convertInt(str.substring(2), 16)); 57 } else if (str.indexOf('.') != -1) 58 { 59 boolean isFloat = false; 60 61 if(str.endsWith("F")) 62 { 63 isFloat = true; 64 str = str.substring(0, str.length() - 1); 65 } 66 67 double x = (new Double (str)).doubleValue(); 68 69 if(isFloat) 70 return new Float ((float)x); 71 else 72 return new Double (x); 73 } else { 74 return (convertInt(str, 10)); 76 } 77 } 78 79 public static String convertDots(String orig_name) 83 { 84 return convertChars(orig_name, ".", '/'); 85 } 86 87 public static String convertChars(String orig_name, 91 String chars, char toChar) 92 { 93 StringBuffer tmp = new StringBuffer (orig_name); 94 int i; 95 for (i = 0; i < tmp.length(); i++) { 96 if (chars.indexOf(tmp.charAt(i)) != -1) { 97 tmp.setCharAt(i, toChar); 98 } 99 } 100 return new String (tmp); 101 } 102 103 public static String [] splitClassMethodSignature(String name) 110 { 111 String result[] = new String [3]; 112 int i, pos = 0, sigpos = 0; 113 for (i = 0; i < name.length(); i++) { 114 char c = name.charAt(i); 115 if (c == '.' || c == '/') pos = i; 116 else if (c == '(') {sigpos = i; break; } 117 } 118 result[0] = convertDots(name.substring(0, pos)); 119 result[1] = name.substring(pos + 1, sigpos); 120 result[2] = convertDots(name.substring(sigpos)); 121 122 return result; 123 } 124 125 public static String [] splitClassField(String name) 132 { 133 String result[] = new String [2]; 134 int i, pos = -1, sigpos = 0; 135 for (i = 0; i < name.length(); i++) { 136 char c = name.charAt(i); 137 if (c == '.' || c == '/') pos = i; 138 } 139 if (pos == -1) { result[0] = null; 141 result[1] = name; 142 } else { 143 result[0] = convertDots(name.substring(0, pos)); 144 result[1] = name.substring(pos + 1); 145 } 146 147 return result; 148 } 149 150 public static String [] splitMethodSignature(String name) 156 { 157 String result[] = new String [2]; 158 int i, sigpos = 0; 159 for (i = 0; i < name.length(); i++) { 160 char c = name.charAt(i); 161 if (c == '(') {sigpos = i; break; } 162 } 163 result[0] = name.substring(0, sigpos); 164 result[1] = convertDots(name.substring(sigpos)); 165 166 return result; 167 } 168 } 169 | Popular Tags |