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 ************************************************************************/
30 public class StringHelper
33 public static String
doubleQuote(String _sStr
)
35 return "\"" + _sStr
+ "\"";
38 public static String
singleQuote(String _sStr
)
40 return "'" + _sStr
+ "'";
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;
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);
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("\"") ||
78 // remove trailing quotes, if exists
79 sNewPath
= sNewPath
.substring(0, sNewPath
.length() - 1);
84 public static String
doubleQuoteIfNeed(String _sStr
)
86 if (_sStr
.startsWith("\"") && _sStr
.endsWith("\""))
91 if (_sStr
.indexOf(" ") == -1)
93 // don't quote, if there is no space in name
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"
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())