MCPcopy Create free account
hub / github.com/SquirrelJME/SquirrelJME / decode

Method decode

runt/apis/cldc-compact/java/lang/Integer.java:184–243  ·  view source on GitHub ↗

Decodes the input string for an integer value. There is an optional sign: - or +. Then the number may be prefixed by: 0x, 0X, or # for hexadecimal, 0 for octal. If there is no prefix then the number is treated as decimal. @param __s The input string

(String __s)

Source from the content-addressed store, hash-verified

182 * @since 2018/11/11
183 */
184 public static Integer decode(String __s)
185 throws NullPointerException, NumberFormatException
186 {
187 if (__s == null)
188 throw new NullPointerException("NARG");
189
190 // {@squirreljme.error ZZ2o Cannot decode an empty string.}
191 if (__s.isEmpty())
192 throw new NumberFormatException("ZZ2o");
193
194 // It may be changed!
195 String orig = __s;
196
197 // Check for sign, assume positive otherwise
198 char sign = __s.charAt(0);
199 if (sign != '-' && sign != '+')
200 sign = '+';
201
202 // Remove the sign
203 else
204 __s = __s.substring(1);
205
206 // Which number format?
207 int radix;
208 if (__s.startsWith("0x") || __s.startsWith("0X"))
209 {
210 radix = 16;
211 __s = __s.substring(2);
212 }
213 else if (__s.startsWith("#"))
214 {
215 radix = 16;
216 __s = __s.substring(1);
217 }
218 else if (__s.startsWith("0"))
219 {
220 radix = 8;
221 __s = __s.substring(1);
222 }
223 else
224 radix = 10;
225
226 // {@squirreljme.error ZZ2o Misplaced sign. (The input string)}
227 if (__s.startsWith("-") || __s.startsWith("+"))
228 throw new NumberFormatException("ZZ2p " + orig);
229
230 // Decode value with radix
231 try
232 {
233 return Integer.parseInt(sign + __s, radix);
234 }
235
236 // {@squirreljme.error ZZ2q Could not parse number. (The input string)}
237 catch (NumberFormatException e)
238 {
239 RuntimeException t = new NumberFormatException("ZZ2q " + orig);
240 t.initCause(e);
241 throw t;

Callers 4

mainMethod · 0.95
testMethod · 0.95
decodeMethod · 0.95
getIntegerMethod · 0.95

Calls 6

parseIntMethod · 0.95
initCauseMethod · 0.80
isEmptyMethod · 0.65
charAtMethod · 0.65
startsWithMethod · 0.65
substringMethod · 0.45

Tested by 2

mainMethod · 0.76
testMethod · 0.76