Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / helper / StringHelper.java
blobd2eb41606844c76a81518a2be73f8b23cae9b48a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package helper;
30 public class StringHelper
33 public static String doubleQuote(String _sStr)
35 return "\"" + _sStr + "\"";
38 public static String singleQuote(String _sStr)
40 return "'" + _sStr + "'";
43 /**
44 * removes quotes if both exists at start and at end
46 public static String removeSurroundQuoteIfExists(String _sPath)
48 String sNewPath = _sPath;
49 boolean bRemoveQuotes = false;
50 if (
51 (_sPath.startsWith("\"") && _sPath.endsWith("\"")) ||
52 (_sPath.startsWith("'") && _sPath.endsWith("'"))
55 // remove trailing quotes, if exists
56 sNewPath = sNewPath.substring(1);
58 // remove trailing quotes, if exists
59 sNewPath = sNewPath.substring(0, sNewPath.length() - 1);
61 return sNewPath;
64 public static String removeQuoteIfExists(String _sPath)
66 String sNewPath = _sPath;
68 if (_sPath.startsWith("\"") ||
69 _sPath.startsWith("'"))
71 // remove trailing quotes, if exists
72 sNewPath = sNewPath.substring(1);
75 if (_sPath.endsWith("\"") ||
76 _sPath.endsWith("'"))
78 // remove trailing quotes, if exists
79 sNewPath = sNewPath.substring(0, sNewPath.length() - 1);
81 return sNewPath;
84 public static String doubleQuoteIfNeed(String _sStr)
86 if (_sStr.startsWith("\"") && _sStr.endsWith("\""))
88 // don't quote twice
89 return _sStr;
91 if (_sStr.indexOf(" ") == -1)
93 // don't quote, if there is no space in name
94 return _sStr;
96 if (_sStr.indexOf("%") != -1)
98 return singleQuote(_sStr);
101 return doubleQuote(_sStr);
105 * Convert a value to a string with a given length, if the len is greater the len of the value string representation
106 * fill it's front with '0'
107 * So ("5", 4) will result in a string "0005"
108 * @param _nValue
109 * @param _nLen
110 * @return
112 public static String createValueString(int _nValue, int _nLen)
114 String sValue = String.valueOf(_nValue);
115 StringBuffer a = new StringBuffer();
116 while (_nLen > sValue.length())
118 a.append('0');
119 _nLen --;
121 a.append(sValue);
122 return a.toString();