package com.fdkankan.common.util;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.fdkankan.common.constant.ErrorCode;

import java.io.File;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jdk.nashorn.internal.runtime.regexp.joni.Regex;

public class StrExtUtil extends StrUtil {

    public static void test(){

        String key = "images/imagest_1/tiles/2k/sfdsdfs_skybox2.png";

        String fileName = key.substring(key.lastIndexOf("/"), key.indexOf("."));
        System.out.println(fileName);
        String[] arr = fileName.split("_skybox");
        String dir = arr[0];
        String num = arr[1];

        String regx = "\\w+.png";

        Pattern compile = Pattern.compile(regx);

        Matcher matcher = compile.matcher(key);

        if(matcher.find()){
            System.out.println(matcher.group());

//            String regx2 = "\\d+";
//
//            Pattern compile2 = Pattern.compile(regx2);
//
//            Matcher matcher2 = compile2.matcher(matcher.group());
//
//            while (matcher2.find()){
//
//                System.out.println(matcher2.group());
//            }
        }



    }

    /**
     * 判断字符串是否包含中文
     * @param content
     * @return
     */
    public static boolean containsZh(String content){
        String regex = "[\u4e00-\u9fa5]+";
        return ReUtil.contains(regex, content);
    }

    public static void main(String[] args) throws Exception {

//        String test = null;
////        System.out.println(test.lastIndexOf("."));
////        System.out.println(test.substring(test.lastIndexOf(".")));
//
//        System.out.println("123".equals(test));;

//        List<String> fileNames = FileUtils.list(new File("C:\\Users\\dsx\\Desktop\\90d95cdb5_202211141023024060"));
//        System.out.println(JSON.toJSONString(fileNames));

        RandomGenerator randomGenerator = new RandomGenerator("0123456789asdfghjklASDFGHJKL", 10);
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(300, 100);
        lineCaptcha.setGenerator(randomGenerator);
        lineCaptcha.write("D:\\test2\\1.png");
        System.out.println(lineCaptcha.getCode());


    }

}
