01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.perseus.parser;
28:
29: /**
30: * The <code>NumberListParser</code> class converts attributes
31: * conforming to the SVG Tiny definition of coordinate or number
32: * list (see <a href="http://www.w3.org/TR/SVG11/types.html#BasicDataTypes">
33: * Basic Data Types</a>)..
34: *
35: * @version $Id: NumberListParser.java,v 1.2 2006/04/21 06:40:19 st125089 Exp $
36: */
37: public class NumberListParser extends NumberParser {
38: /**
39: * @param listStr the string containing the list of numbers
40: * @param sep the separator between number values
41: * @return An array of numbers
42: */
43: public float[] parseNumberList(final String listStr, final char sep) {
44: setString(listStr);
45:
46: current = read();
47: skipSpaces();
48:
49: boolean requireMore = false;
50: float[] numbers = null;
51: int cur = 0;
52: for (;;) {
53: if (current != -1) {
54: float v = parseNumber(false);
55: if (numbers == null) {
56: numbers = new float[1];
57: } else if (numbers.length <= cur) {
58: float[] tmpNumbers = new float[numbers.length * 2];
59: System.arraycopy(numbers, 0, tmpNumbers, 0,
60: numbers.length);
61: numbers = tmpNumbers;
62: }
63: numbers[cur++] = v;
64: } else {
65: if (!requireMore) {
66: break;
67: } else {
68: throw new IllegalArgumentException();
69: }
70: }
71: skipSpaces();
72: requireMore = (current == sep);
73: skipSepSpaces(sep);
74: }
75:
76: if (numbers != null && cur != numbers.length) {
77: float[] tmpNumbers = new float[cur];
78: System.arraycopy(numbers, 0, tmpNumbers, 0, cur);
79: numbers = tmpNumbers;
80: }
81:
82: return numbers;
83: }
84:
85: /**
86: * @param listStr the string containing the list of numbers
87: * @return An array of numbers
88: */
89: public float[] parseNumberList(final String listStr) {
90: return parseNumberList(listStr, ',');
91: }
92: }
|