2
2
* ProGuard -- shrinking, optimization, obfuscation, and preverification
5
* Copyright (c) 2002-2008 Eric Lafortune (eric@graphics.cornell.edu)
5
* Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
7
7
* This program is free software; you can redistribute it and/or modify it
8
8
* under the terms of the GNU General Public License as published by the Free
70
70
List list = new ArrayList();
72
while (index < string.length())
72
while ((index = skipWhitespace(string, index)) < string.length())
74
int nextIndex = string.indexOf(',', index);
77
nextIndex = string.length();
80
list.add(string.substring(index, nextIndex).trim());
76
// Do we have an opening quote?
77
if (string.charAt(index) == '\'')
79
// Parse a quoted string.
80
nextIndex = string.indexOf('\'', index + 1);
83
nextIndex = string.length();
86
list.add(string.substring(index + 1, nextIndex));
90
// Parse a non-quoted string.
91
nextIndex = string.indexOf(',', index);
94
nextIndex = string.length();
97
String substring = string.substring(index, nextIndex).trim();
98
if (substring.length() > 0)
82
104
index = nextIndex + 1;
112
* Skips any whitespace characters.
114
private static int skipWhitespace(String string, int index)
116
while (index < string.length() &&
117
Character.isWhitespace(string.charAt(index)))
126
* Returns a quoted version of the given string, if necessary.
128
private static String quotedString(String string)
130
return string.length() == 0 ||
131
string.indexOf(' ') >= 0 ||
132
string.indexOf('@') >= 0 ||
133
string.indexOf('{') >= 0 ||
134
string.indexOf('}') >= 0 ||
135
string.indexOf('(') >= 0 ||
136
string.indexOf(')') >= 0 ||
137
string.indexOf(':') >= 0 ||
138
string.indexOf(';') >= 0 ||
139
string.indexOf(',') >= 0 ? ("'" + string + "'") :
144
public static void main(String[] args)
146
if (args.length == 1)
148
System.out.println("Input string: ["+args[0]+"]");
150
List list = commaSeparatedList(args[0]);
152
System.out.println("Resulting list:");
153
for (int index = 0; index < list.size(); index++)
155
System.out.println("["+list.get(index)+"]");
160
List list = Arrays.asList(args);
162
System.out.println("Input list:");
163
for (int index = 0; index < list.size(); index++)
165
System.out.println("["+list.get(index)+"]");
168
String string = commaSeparatedString(list);
170
System.out.println("Resulting string: ["+string+"]");