package com.microservices.cms.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author otto
 */
public class CmsUtils {
    /**
     * 去除字符串中的空格、回车、换行符、制表符
     */
    private static final Pattern p = Pattern.compile("\\s*|\t|\r|\n");

    public static String getFileNameNoSuffix(String fileName) {
        int lastIndex = fileName.lastIndexOf(".");
        return fileName.substring(0, lastIndex);
    }


    public static String getFileSuffix(String fileName) {
        Matcher m = p.matcher(fileName);
        fileName = m.replaceAll("");
        return fileName.replaceAll(".*(\\..*)", "$1").toLowerCase();
    }
}
