1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 ************************************************************************/
33 public class StringHelper
36 public static String
doubleQuote(String _sStr
)
38 return "\"" + _sStr
+ "\"";
41 public static String
singleQuote(String _sStr
)
43 return "'" + _sStr
+ "'";
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;
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);
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("\"") ||
81 // remove trailing quotes, if exists
82 sNewPath
= sNewPath
.substring(0, sNewPath
.length() - 1);
87 public static String
doubleQuoteIfNeed(String _sStr
)
89 if (_sStr
.startsWith("\"") && _sStr
.endsWith("\""))
94 if (_sStr
.indexOf(" ") == -1)
96 // don't quote, if there is no space in name
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"
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())