Update ooo320-m1
[ooovba.git] / qadevOOo / runner / helper / StringHelper.java
blob1a8339714bf28b9da7323f37a0170ffdc1c8be26
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: StringHelper.java,v $
10 * $Revision: 1.1.2.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package helper;
33 public class StringHelper
36 public static String doubleQuote(String _sStr)
38 return "\"" + _sStr + "\"";
41 public static String singleQuote(String _sStr)
43 return "'" + _sStr + "'";
46 /**
47 * removes quotes if both exists at start and at end
49 public static String removeSurroundQuoteIfExists(String _sPath)
51 String sNewPath = _sPath;
52 boolean bRemoveQuotes = false;
53 if (
54 (_sPath.startsWith("\"") && _sPath.endsWith("\"")) ||
55 (_sPath.startsWith("'") && _sPath.endsWith("'"))
58 // remove trailing quotes, if exists
59 sNewPath = sNewPath.substring(1);
61 // remove trailing quotes, if exists
62 sNewPath = sNewPath.substring(0, sNewPath.length() - 1);
64 return sNewPath;
67 public static String removeQuoteIfExists(String _sPath)
69 String sNewPath = _sPath;
71 if (_sPath.startsWith("\"") ||
72 _sPath.startsWith("'"))
74 // remove trailing quotes, if exists
75 sNewPath = sNewPath.substring(1);
78 if (_sPath.endsWith("\"") ||
79 _sPath.endsWith("'"))
81 // remove trailing quotes, if exists
82 sNewPath = sNewPath.substring(0, sNewPath.length() - 1);
84 return sNewPath;
87 public static String doubleQuoteIfNeed(String _sStr)
89 if (_sStr.startsWith("\"") && _sStr.endsWith("\""))
91 // don't quote twice
92 return _sStr;
94 if (_sStr.indexOf(" ") == -1)
96 // don't quote, if there is no space in name
97 return _sStr;
99 if (_sStr.indexOf("%") != -1)
101 return singleQuote(_sStr);
104 return doubleQuote(_sStr);
108 * Convert a value to a string with a given length, if the len is greater the len of the value string representation
109 * fill it's front with '0'
110 * So ("5", 4) will result in a string "0005"
111 * @param _nValue
112 * @param _nLen
113 * @return
115 public static String createValueString(int _nValue, int _nLen)
117 String sValue = String.valueOf(_nValue);
118 StringBuffer a = new StringBuffer();
119 while (_nLen > sValue.length())
121 a.append('0');
122 _nLen --;
124 a.append(sValue);
125 return a.toString();