bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / helper / StringHelper.java
blobf2921906ca0a226242346b295a34ef769717f0f9
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package helper;
21 public class StringHelper
24 public static String doubleQuote(String _sStr)
26 return "\"" + _sStr + "\"";
29 public static String singleQuote(String _sStr)
31 return "'" + _sStr + "'";
34 /**
35 * removes quotes if both exists at start and at end
37 public static String removeSurroundQuoteIfExists(String _sPath)
39 String sNewPath = _sPath;
40 if (
41 (_sPath.startsWith("\"") && _sPath.endsWith("\"")) ||
42 (_sPath.startsWith("'") && _sPath.endsWith("'"))
45 // remove trailing quotes, if exists
46 sNewPath = sNewPath.substring(1);
48 // remove trailing quotes, if exists
49 sNewPath = sNewPath.substring(0, sNewPath.length() - 1);
51 return sNewPath;
54 public static String removeQuoteIfExists(String _sPath)
56 String sNewPath = _sPath;
58 if (_sPath.startsWith("\"") ||
59 _sPath.startsWith("'"))
61 // remove trailing quotes, if exists
62 sNewPath = sNewPath.substring(1);
65 if (_sPath.endsWith("\"") ||
66 _sPath.endsWith("'"))
68 // remove trailing quotes, if exists
69 sNewPath = sNewPath.substring(0, sNewPath.length() - 1);
71 return sNewPath;
74 public static String doubleQuoteIfNeed(String _sStr)
76 if (_sStr.startsWith("\"") && _sStr.endsWith("\""))
78 // don't quote twice
79 return _sStr;
81 if (_sStr.indexOf(" ") == -1)
83 // don't quote, if there is no space in name
84 return _sStr;
86 if (_sStr.indexOf("%") != -1)
88 return singleQuote(_sStr);
91 return doubleQuote(_sStr);
94 /**
95 * Convert a value to a string with a given length, if the len is greater the len of the value string representation
96 * fill it's front with '0'
97 * So ("5", 4) will result in a string "0005"
98 * @param _nValue
99 * @param _nLen
100 * @return
102 public static String createValueString(int _nValue, int _nLen)
104 String sValue = String.valueOf(_nValue);
105 StringBuffer a = new StringBuffer();
106 while (_nLen > sValue.length())
108 a.append('0');
109 _nLen --;
111 a.append(sValue);
112 return a.toString();