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 * @version $Id: Util.java 1443102 2013-02-06 18:12:16Z tn $
24 */
25 final class Util
26 {
27 /**
28 * Remove the hyphens from the beginning of <code>str</code> and
29 * return the new String.
30 *
31 * @param str The string from which the hyphens should be removed.
32 *
33 * @return the new String.
34 */
35 static String stripLeadingHyphens(String str)
36 {
37 if (str == null)
38 {
39 return null;
40 }
41 if (str.startsWith("--"))
42 {
43 return str.substring(2, str.length());
44 }
45 else if (str.startsWith("-"))
46 {
47 return str.substring(1, str.length());
48 }
49
50 return str;
51 }
52
53 /**
54 * Remove the leading and trailing quotes from <code>str</code>.
55 * E.g. if str is '"one two"', then 'one two' is returned.
56 *
57 * @param str The string from which the leading and trailing quotes
58 * should be removed.
59 *
60 * @return The string without the leading and trailing quotes.
61 */
62 static String stripLeadingAndTrailingQuotes(String str)
63 {
64 int length = str.length();
65 if (length > 1 && str.startsWith("\"") && str.endsWith("\"") && str.substring(1, length - 1).indexOf('"') == -1)
66 {
67 str = str.substring(1, length - 1);
68 }
69
70 return str;
71 }
72 }