/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/Parser.java
ViewVC logotype

Diff of /jlscp/trunk/src/org/linuxsampler/lscp/Parser.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1138 by iliev, Mon Oct 10 14:55:44 2005 UTC revision 1139 by iliev, Mon Apr 2 20:43:58 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *   jlscp - a java LinuxSampler control protocol API   *   jlscp - a java LinuxSampler control protocol API
3   *   *
4   *   Copyright (C) 2005 Grigor Kirilov Iliev   *   Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of jlscp.   *   This file is part of jlscp.
7   *   *
# Line 32  import java.util.Vector; Line 32  import java.util.Vector;
32   * @author  Grigor Iliev   * @author  Grigor Iliev
33   */   */
34  final class Parser {  final class Parser {
35            /** Forbits the instantiatrion of this class */
36            private Parser() { }
37            
38          /**          /**
39           * Parses an integer value.           * Parses an integer value.
40           * @param s The integer value to be parsed.           * @param s The integer value to be parsed.
# Line 65  final class Parser { Line 68  final class Parser {
68           * @return A <code>String</code> array containing all items in the list.           * @return A <code>String</code> array containing all items in the list.
69           */           */
70          protected static String[]          protected static String[]
71          parseList(String list) {          parseList(String list) { return parseList(list, ','); }
72            
73            /**
74             * Parses a list.
75             * @param list The list to parse.
76             * @param separator Provides the character used as separator.
77             * @return A <code>String</code> array containing all items in the list.
78             */
79            protected static String[]
80            parseList(String list, char separator) {
81                  if(list == null || list.length() == 0) return new String[0];                  if(list == null || list.length() == 0) return new String[0];
82                  int pos = 0;                  int pos = 0;
83                  int idx;                  int idx;
84                  Vector<String> v = new Vector<String>();                  Vector<String> v = new Vector<String>();
85                  while((idx = list.indexOf(',', pos)) > 0) {                  while((idx = list.indexOf(separator, pos)) > 0) {
86                          v.add(list.substring(pos, idx));                          v.add(list.substring(pos, idx));
87                          pos = idx + 1;                          pos = idx + 1;
88                  }                  }
# Line 106  final class Parser { Line 118  final class Parser {
118           * @throws LscpException if the list contains value(s) from different type.           * @throws LscpException if the list contains value(s) from different type.
119           */           */
120          protected static Integer[]          protected static Integer[]
121          parseIntList(String list) throws LscpException {          parseIntList(String list) throws LscpException { return parseIntList(list, ','); }
122                  String[] ar = parseList(list);          
123            /**
124             * Parses a list of integer values.
125             *
126             * @param list The list of integer values.
127             * @param separator Provides the character used as separator.
128             * @return A <code>Integer</code> array containing all items in the list.
129             *
130             * @throws LscpException if the list contains value(s) from different type.
131             */
132            protected static Integer[]
133            parseIntList(String list, char separator) throws LscpException {
134            String[] ar = parseList(list, separator);
135                                    
136                  Integer[] iar = new Integer[ar.length];                  Integer[] iar = new Integer[ar.length];
137                  for(int i = 0; i < ar.length; i++) iar[i] = parseInt(ar[i]);                  for(int i = 0; i < ar.length; i++) iar[i] = parseInt(ar[i]);
# Line 195  final class Parser { Line 219  final class Parser {
219                  return s2S;                  return s2S;
220          }          }
221                    
222            /**
223             * Parses a comma separated list whose items are encapsulated into curly braces.
224             *
225             * @param list The comma separated list.
226             * @return A <code>String</code> array containing all items in the list.
227             *
228             * @throws LscpException if the list is broken.
229             */
230            protected static String[]
231            parseArray(String list) throws LscpException {
232                    if(list == null || list.length() == 0) return new String[0];
233                    int q1 = 0, q2 = 0;
234                    Vector<String> v = new Vector<String>();
235                    
236                    for(;;) {
237                            if(list.charAt(q1) != '{')
238                                    throw new LscpException(LscpI18n.getLogMsg("Parser.brokenList!"));
239                            q2 = list.indexOf('}', q1 + 1);
240                            if(q2 == -1) throw new LscpException(LscpI18n.getLogMsg("Parser.EOL!"));
241                            v.add(list.substring(q1 + 1, q2));
242                            
243                            if(q2 + 1 >= list.length()) break;
244                            
245                            if(list.charAt(q2 + 1) != ',')
246                                    throw new LscpException(LscpI18n.getLogMsg("Parser.brokenList!"));
247                            q1 = q2 + 2;
248                            if(q1 >= list.length())
249                                    throw new LscpException(LscpI18n.getLogMsg("Parser.EOL!"));
250                    }
251                    
252                    return v.toArray(new String[v.size()]);
253            }
254            
255          /** Helper function used by <code>parseListOfStringLists</code>. */          /** Helper function used by <code>parseListOfStringLists</code>. */
256          private static int          private static int
257          getEndListIndex(int start, String list) throws LscpException {          getEndListIndex(int start, String list) throws LscpException {

Legend:
Removed from v.1138  
changed lines
  Added in v.1139

  ViewVC Help
Powered by ViewVC