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 package org.apache.commons.cli; 18 19 /*** 20 * Contains useful helper methods for classes within this package. 21 * 22 * @author John Keyes (john at integralsource.com) 23 */ 24 class Util { 25 26 /*** 27 * <p>Remove the hyphens from the begining of <code>str</code> and 28 * return the new String.</p> 29 * 30 * @param str The string from which the hyphens should be removed. 31 * 32 * @return the new String. 33 */ 34 static String stripLeadingHyphens(String str) 35 { 36 if (str == null) { 37 return null; 38 } 39 if (str.startsWith("--")) 40 { 41 return str.substring(2, str.length()); 42 } 43 else if (str.startsWith("-")) 44 { 45 return str.substring(1, str.length()); 46 } 47 48 return str; 49 } 50 51 /*** 52 * Remove the leading and trailing quotes from <code>str</code>. 53 * E.g. if str is '"one two"', then 'one two' is returned. 54 * 55 * @param str The string from which the leading and trailing quotes 56 * should be removed. 57 * 58 * @return The string without the leading and trailing quotes. 59 */ 60 static String stripLeadingAndTrailingQuotes(String str) 61 { 62 if (str.startsWith("\"")) { 63 str = str.substring(1, str.length()); 64 } 65 if (str.endsWith("\"")) { 66 str = str.substring(0, str.length()-1); 67 } 68 return str; 69 } 70 }