Skip to content

Commit c0d5c79

Browse files
author
John Keyes
committed
removed the leading and trailing spaces from multi token option values
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129874 13f79535-47bb-0310-9956-ffa450edef68
1 parent 326ac6d commit c0d5c79

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

src/java/org/apache/commons/cli/Parser.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Parser.java,v 1.11 2002/12/09 23:47:25 jkeyes Exp $
3-
* $Revision: 1.11 $
4-
* $Date: 2002/12/09 23:47:25 $
2+
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Parser.java,v 1.12 2003/01/17 20:00:14 jkeyes Exp $
3+
* $Revision: 1.12 $
4+
* $Date: 2003/01/17 20:00:14 $
55
*
66
* ====================================================================
77
*
@@ -72,7 +72,7 @@
7272
*
7373
* @author John Keyes (john at integralsource.com)
7474
* @see Parser
75-
* @version $Revision: 1.11 $
75+
* @version $Revision: 1.12 $
7676
*/
7777
public abstract class Parser implements CommandLineParser {
7878

@@ -375,9 +375,10 @@ public void processArgs(Option opt, ListIterator iter)
375375
// found a value
376376
else
377377
{
378+
378379
try
379380
{
380-
opt.addValue(str);
381+
opt.addValue( Util.stripLeadingAndTrailingQuotes(str) );
381382
}
382383
catch (RuntimeException exp)
383384
{

src/java/org/apache/commons/cli/Util.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Util.java,v 1.2 2002/12/09 23:47:25 jkeyes Exp $
3-
* $Revision: 1.2 $
4-
* $Date: 2002/12/09 23:47:25 $
2+
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Util.java,v 1.3 2003/01/17 20:00:14 jkeyes Exp $
3+
* $Revision: 1.3 $
4+
* $Date: 2003/01/17 20:00:14 $
55
*
66
* ====================================================================
77
*
@@ -73,8 +73,7 @@ class Util {
7373
*
7474
* @param str The string from which the hyphens should be removed.
7575
*
76-
* @return the hyphens from the begining of <code>str</code> and
77-
* return the new String.
76+
* @return the new String.
7877
*/
7978
static String stripLeadingHyphens(String str)
8079
{
@@ -89,4 +88,24 @@ else if (str.startsWith("-"))
8988

9089
return str;
9190
}
91+
92+
/**
93+
* <p>Remove the leading and trailing quotes from <code>str</code>,
94+
* e.g. if str is '"one two"', then 'one two' is returned.</p>
95+
*
96+
* @param str The string from which the leading and trailing quotes
97+
* should be removed.
98+
*
99+
* @return The string without the leading and trailing quotes.
100+
*/
101+
static String stripLeadingAndTrailingQuotes(String str)
102+
{
103+
if (str.startsWith("\"")) {
104+
str = str.substring(1, str.length());
105+
}
106+
if (str.endsWith("\"")) {
107+
str = str.substring(0, str.length()-1);
108+
}
109+
return str;
110+
}
92111
}

src/test/org/apache/commons/cli/BugsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* version 1.1, a copy of which has been included with this distribution in
66
* the LICENSE file.
77
*
8-
* $Id: BugsTest.java,v 1.15 2003/01/16 23:06:52 jkeyes Exp $
8+
* $Id: BugsTest.java,v 1.16 2003/01/17 20:00:14 jkeyes Exp $
99
*/
1010

1111
package org.apache.commons.cli;
@@ -381,7 +381,7 @@ public void test15648() throws Exception {
381381
Options options = new Options();
382382
options.addOption( m );
383383
CommandLine line = parser.parse( options, args );
384-
assertEquals( "\"Two Words\"", line.getOptionValue( "m" ) );
384+
assertEquals( "Two Words", line.getOptionValue( "m" ) );
385385
}
386386

387387
}

0 commit comments

Comments
 (0)