01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.commons.cli;
17:
18: /**
19: * Contains useful helper methods for classes within this package.
20: *
21: * @author John Keyes (john at integralsource.com)
22: */
23: class Util {
24:
25: /**
26: * <p>Remove the hyphens from the begining of <code>str</code> and
27: * return the new String.</p>
28: *
29: * @param str The string from which the hyphens should be removed.
30: *
31: * @return the new String.
32: */
33: static String stripLeadingHyphens(String str) {
34: if (str == null) {
35: return null;
36: }
37: if (str.startsWith("--")) {
38: return str.substring(2, str.length());
39: } else if (str.startsWith("-")) {
40: return str.substring(1, str.length());
41: }
42:
43: return str;
44: }
45:
46: /**
47: * Remove the leading and trailing quotes from <code>str</code>.
48: * E.g. if str is '"one two"', then 'one two' is returned.
49: *
50: * @param str The string from which the leading and trailing quotes
51: * should be removed.
52: *
53: * @return The string without the leading and trailing quotes.
54: */
55: static String stripLeadingAndTrailingQuotes(String str) {
56: if (str.startsWith("\"")) {
57: str = str.substring(1, str.length());
58: }
59: if (str.endsWith("\"")) {
60: str = str.substring(0, str.length() - 1);
61: }
62: return str;
63: }
64: }
|