Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/******************************************************************************
* Copyright 2009-2018 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.exactpro.sf.common.util;
import static java.lang.Character.isWhitespace;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
public class StringUtil {
public static final String EOL = System.getProperty("line.separator");
private StringUtil()
{
// hide constructor
}
private static final int shift = 'a' - 'A';
private static final String DEFAULT_ENCODING = "UTF-8";
private static final Pattern FORBIDDEN_FILENAME_ELEMENTS = Pattern.compile("<|>|:|\"|\\/|\\\\|\\||\\?|\\*|[\\x00-\\x1F]|(\\.|\\s)$|^(CON|PRN|AUX|NUL|COM\\d|LPT\\d)$");
public static void main(String[] args) {
validateFileName("str/dgfg");
}
/**
* Capitalize word. Search in input string first character "a-z,A-Z" and
* let it be in upper case. Other word characters will be in lower case.
* @param s string to be capitalized
* @return capitalized string
*/
public static String capitalize(String s)
{
StringBuilder sb = new StringBuilder(s.length());
boolean isFirst = true;
for (byte b : s.getBytes())
{
if (b >= 'a' && b <= 'z')
{
if (isFirst) {
b -= shift;
isFirst = false;
}
} else if (b >= 'A' && b <= 'Z')
{
if (isFirst) {
isFirst = false;
} else {
b += shift;
}
}
sb.append((char)b);
}
return sb.toString();
}
/**
* Capitalize all strings in array. In each word find first character
* "a-z,A-Z" and convert it to upper case.
* Other characters will be converted to lower case.
* @param s array of strings to be capitalized
* @return array of capitalized strings
*/
public static String[] capitalize(String[] s) {
String[] ss = new String[s.length];
for (int i=0; i
*
* Example:
*
* join("_", new String[] {"Hello", "world", ""})
* will return "Hello_world_"
*
* @param delim string delimiter
* @param arr array of strings to be joined
* @return joined string
*/
public static String join(String delim, String[] arr)
{
StringBuilder sb = new StringBuilder();
for (int i=0; i
*
* Example:
*
* join("_", new String[] {"Hello", "world", ""})
* will return "Hello_world_"
*