@@ -38,22 +38,18 @@ public class PosixParser extends Parser {
3838 /** specifies if bursting should continue */
3939 private boolean eatTheRest ;
4040
41- /** holder for the current option */
42- private Option currentOption ;
43-
4441 /** the command line Options */
4542 private Options options ;
4643
4744 /**
4845 * Resets the members to their original state i.e. remove
49- * all of <code>tokens</code> entries, set <code>eatTheRest</code>
50- * to false and set <code>currentOption</code> to null .
46+ * all of <code>tokens</code> entries and set <code>eatTheRest</code>
47+ * to false.
5148 */
5249 private void init ()
5350 {
5451 eatTheRest = false ;
5552 tokens .clear ();
56- currentOption = null ;
5753 }
5854
5955 /**
@@ -116,7 +112,7 @@ protected String[] flatten(Options options, String[] arguments, boolean stopAtNo
116112
117113 if (!options .hasOption (opt ) && stopAtNonOption )
118114 {
119- process (token );
115+ processNonOptionToken (token );
120116 }
121117 else
122118 {
@@ -150,7 +146,7 @@ else if (options.hasOption(token))
150146 }
151147 else if (stopAtNonOption )
152148 {
153- process (token );
149+ processNonOptionToken (token );
154150 }
155151 else
156152 {
@@ -180,62 +176,34 @@ private void gobble(Iterator iter)
180176 }
181177
182178 /**
183- * <p>If there is a current option and it can have an argument
184- * value then add the token to the processed tokens list and
185- * set the current option to null.</p>
186- *
187- * <p>If there is a current option and it can have argument
188- * values then add the token to the processed tokens list.</p>
189- *
190- * <p>If there is not a current option add the special token
191- * "<b>--</b>" and the current <code>value</code> to the processed
192- * tokens list. The add all the remaining <code>argument</code>
193- * values to the processed tokens list.</p>
179+ * Add the special token "<b>--</b>" and the current <code>value</code>
180+ * to the processed tokens list. Then add all the remaining
181+ * <code>argument</code> values to the processed tokens list.
194182 *
195183 * @param value The current token
196184 */
197- private void process (String value )
185+ private void processNonOptionToken (String value )
198186 {
199- if (currentOption != null && currentOption .hasArg ())
200- {
201- if (currentOption .hasArg ())
202- {
203- tokens .add (value );
204- currentOption = null ;
205- }
206- else if (currentOption .hasArgs ())
207- {
208- tokens .add (value );
209- }
210- }
211- else
212- {
213- eatTheRest = true ;
214- tokens .add ("--" );
215- tokens .add (value );
216- }
187+ eatTheRest = true ;
188+ tokens .add ("--" );
189+ tokens .add (value );
217190 }
218191
219192 /**
220193 * <p>If an {@link Option} exists for <code>token</code> then
221- * set the current option and add the token to the processed
222- * list.</p>
194+ * add the token to the processed list.</p>
223195 *
224196 * <p>If an {@link Option} does not exist and <code>stopAtNonOption</code>
225- * is set then ignore the current token and add the remaining tokens
226- * to the processed tokens list directly.</p>
197+ * is set then add the remaining tokens to the processed tokens list
198+ * directly.</p>
227199 *
228200 * @param token The current option token
229201 * @param stopAtNonOption Specifies whether flattening should halt
230202 * at the first non option.
231203 */
232204 private void processOptionToken (String token , boolean stopAtNonOption )
233205 {
234- if (options .hasOption (token ))
235- {
236- currentOption = options .getOption (token );
237- }
238- else if (stopAtNonOption )
206+ if (!options .hasOption (token ) && stopAtNonOption )
239207 {
240208 eatTheRest = true ;
241209 }
@@ -271,6 +239,8 @@ else if (stopAtNonOption)
271239 */
272240 protected void burstToken (String token , boolean stopAtNonOption )
273241 {
242+ Option currentOption ;
243+
274244 for (int i = 1 ; i < token .length (); i ++)
275245 {
276246 String ch = String .valueOf (token .charAt (i ));
@@ -289,7 +259,7 @@ protected void burstToken(String token, boolean stopAtNonOption)
289259 }
290260 else if (stopAtNonOption )
291261 {
292- process (token .substring (i ));
262+ processNonOptionToken (token .substring (i ));
293263 break ;
294264 }
295265 else
0 commit comments