1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.cli;
19
20 /**
21 * Contains useful helper methods for classes within this package.
22 *
23 * @author John Keyes (john at integralsource.com)
24 * @version $Revision: 680644 $, $Date: 2008-07-29 09:13:48 +0100 (Tue, 29 Jul 2008) $
25 */
26 class Util
27 {
28 /**
29 * Remove the hyphens from the begining of <code>str</code> and
30 * return the new String.
31 *
32 * @param str The string from which the hyphens should be removed.
33 *
34 * @return the new String.
35 */
36 static String stripLeadingHyphens(String str)
37 {
38 if (str == null)
39 {
40 return null;
41 }
42 if (str.startsWith("--"))
43 {
44 return str.substring(2, str.length());
45 }
46 else if (str.startsWith("-"))
47 {
48 return str.substring(1, str.length());
49 }
50
51 return str;
52 }
53
54 /**
55 * Remove the leading and trailing quotes from <code>str</code>.
56 * E.g. if str is '"one two"', then 'one two' is returned.
57 *
58 * @param str The string from which the leading and trailing quotes
59 * should be removed.
60 *
61 * @return The string without the leading and trailing quotes.
62 */
63 static String stripLeadingAndTrailingQuotes(String str)
64 {
65 if (str.startsWith("\""))
66 {
67 str = str.substring(1, str.length());
68 }
69 if (str.endsWith("\""))
70 {
71 str = str.substring(0, str.length() - 1);
72 }
73 return str;
74 }
75 }