01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.util;
12:
13: /**
14: * Static utility methods for parsing primitives from String's without
15: * creating any objects.
16: */
17: public class FastParser {
18:
19: /**
20: * Parse the int at index from value. The int is assumed to run until
21: * the end of the String.
22: */
23: public static int parseInt(String value, int index) {
24: char c = value.charAt(index++);
25: int ans;
26: if (c == '-')
27: ans = -(value.charAt(index++) - '0');
28: else
29: ans = c - '0';
30: int n = value.length();
31: for (; index < n;) {
32: ans = ans * 10 + (value.charAt(index++) - '0');
33: }
34: return ans;
35: }
36:
37: /**
38: * Parse the long at index from value. The long is assumed to run until
39: * the end of the String.
40: */
41: public static long parseLong(String value, int index) {
42: char c = value.charAt(index++);
43: long ans;
44: if (c == '-')
45: ans = -(value.charAt(index++) - '0');
46: else
47: ans = c - '0';
48: int n = value.length();
49: for (; index < n;) {
50: ans = ans * 10 + (value.charAt(index++) - '0');
51: }
52: return ans;
53: }
54:
55: }
|