package com.diabin.fastec.util.string;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * Created by 傅令杰 on 2016/10/10
 */

public final class StringUtil {

    //首字母转小写
    public static String toLowerCaseFirstOne(String s) {
        if (Character.isLowerCase(s.charAt(0)))
            return s;
        else
            return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
    }

    //首字母转大写
    public static String toUpperCaseFirstOne(String s) {
        if (Character.isUpperCase(s.charAt(0)))
            return s;
        else
            return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
    }

    /**
     * 检查一个字符串是否全部包含列举出来的字符串
     */
    public static boolean containsAll(String str, String... strings) {
        int count = 0;
        for (String item : strings) {
            if (str.contains(item)) {
                count++;
            }
        }
        return count == (strings.length - 1);
    }

    /**
     * 检查一个字符串是否包含其中之一的字符串
     */
    public static boolean containsOne(String str, String... strings) {
        for (String item : strings) {
            if (str.contains(item)) {
                return true;
            }
        }
        return false;
    }

    public static String convertUTF8(String str) {
        try {
            return URLDecoder.decode(str, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return str;
        }
    }

}
