package org.jeecg.module.custom.ocr.utils;

public class NameConverterUtil {
    /**
     * 将驼峰命名转换为下划线命名
     * 例如：createTime -> create_time, userFirstName -> user_first_name
     * @param camelCase 驼峰命名的字符串
     * @return 下划线命名的字符串
     */
    public static String camelToSnakeCase(String camelCase) {
        if (camelCase == null || camelCase.isEmpty()) {
            return camelCase;
        }

        StringBuilder result = new StringBuilder();
        // 遍历每个字符
        for (int i = 0; i < camelCase.length(); i++) {
            char c = camelCase.charAt(i);
            // 如果是大写字母，添加下划线并转换为小写
            if (Character.isUpperCase(c)) {
                result.append('_').append(Character.toLowerCase(c));
            } else {
                result.append(c);
            }
        }

        return result.toString();
    }
}
