package com.zanxiang.game.data.serve.utils;

/**
 * packageName com.zanxiang.game.data.serve.utils
 *
 * @author ZhangXianyu
 * @date 2025/5/7
 * @description TODO
 */
public class StringUtils {

    /**
     * 转驼峰转下划线
     * @param camelCase
     * @return
     */
    public static String camelToSnake(String camelCase) {
        if (camelCase == null || camelCase.isEmpty()) {
            return camelCase;
        }
        // 处理连续大写字母（如 "HTTPRequest" → "HTTP_Request"）
        String step1 = camelCase.replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2");
        // 处理小写后跟大写字母（如 "userName" → "user_Name"）
        String step2 = step1.replaceAll("([a-z])([A-Z])", "$1_$2");
        // 统一转小写并用下划线连接
        return step2.toLowerCase().replace(' ', '_');
    }


}