package com.xjrsoft.common.utils;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

/**
 * @Author: tzx
 * @Date: 2022/8/26 10:24
 */
@Data
public class XjrStringUtil {
    public static String toCamelCase(CharSequence name) {
        return toCamelCase(name, '_');
    }

    public static String toCamelCase(CharSequence name, char symbol) {
        if (null == name) {
            return null;
        } else {
            String name2 = name.toString();
            if (StrUtil.contains(name2, symbol)) {
                int length = name2.length();
                StringBuilder sb = new StringBuilder(length);
                boolean upperCase = false;

                for (int i = 0; i < length; ++i) {
                    char c = name2.charAt(i);
                    if (c == symbol) {
                        upperCase = true;
                    } else if (upperCase) {
                        sb.append(Character.toUpperCase(c));
                        upperCase = false;
                    } else {
                        sb.append(c);
                    }
                }

                return sb.toString();
            } else {
                return name2;
            }
        }
    }
}
