You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2003/01/17 21:00:14 UTC
cvs commit: jakarta-commons/cli/src/java/org/apache/commons/cli Parser.java Util.java
jkeyes 2003/01/17 12:00:14
Modified: cli/src/test/org/apache/commons/cli BugsTest.java
cli/src/java/org/apache/commons/cli Parser.java Util.java
Log:
removed the leading and trailing spaces from multi token option values
Revision Changes Path
1.16 +2 -2 jakarta-commons/cli/src/test/org/apache/commons/cli/BugsTest.java
Index: BugsTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/BugsTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- BugsTest.java 16 Jan 2003 23:06:52 -0000 1.15
+++ BugsTest.java 17 Jan 2003 20:00:14 -0000 1.16
@@ -381,7 +381,7 @@
Options options = new Options();
options.addOption( m );
CommandLine line = parser.parse( options, args );
- assertEquals( "\"Two Words\"", line.getOptionValue( "m" ) );
+ assertEquals( "Two Words", line.getOptionValue( "m" ) );
}
}
1.12 +6 -5 jakarta-commons/cli/src/java/org/apache/commons/cli/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Parser.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Parser.java 9 Dec 2002 23:47:25 -0000 1.11
+++ Parser.java 17 Jan 2003 20:00:14 -0000 1.12
@@ -375,9 +375,10 @@
// found a value
else
{
+
try
{
- opt.addValue(str);
+ opt.addValue( Util.stripLeadingAndTrailingQuotes(str) );
}
catch (RuntimeException exp)
{
1.3 +24 -5 jakarta-commons/cli/src/java/org/apache/commons/cli/Util.java
Index: Util.java
===================================================================
RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Util.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Util.java 9 Dec 2002 23:47:25 -0000 1.2
+++ Util.java 17 Jan 2003 20:00:14 -0000 1.3
@@ -73,8 +73,7 @@
*
* @param str The string from which the hyphens should be removed.
*
- * @return the hyphens from the begining of <code>str</code> and
- * return the new String.
+ * @return the new String.
*/
static String stripLeadingHyphens(String str)
{
@@ -87,6 +86,26 @@
return str.substring(1, str.length());
}
+ return str;
+ }
+
+ /**
+ * <p>Remove the leading and trailing quotes from <code>str</code>,
+ * e.g. if str is '"one two"', then 'one two' is returned.</p>
+ *
+ * @param str The string from which the leading and trailing quotes
+ * should be removed.
+ *
+ * @return The string without the leading and trailing quotes.
+ */
+ static String stripLeadingAndTrailingQuotes(String str)
+ {
+ if (str.startsWith("\"")) {
+ str = str.substring(1, str.length());
+ }
+ if (str.endsWith("\"")) {
+ str = str.substring(0, str.length()-1);
+ }
return str;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>