package cn.estsh.i3plus.ext.mes.pcn.apiservice.util;

public class StringUtilExt {

    public static String stringFormat(String data, Integer length,String symbol) {
        return stringFormat(data, length, true, symbol);
    }

    public static String stringFormat(String data, Integer length, boolean left, String symbol) {
        //数据长途大于填充位数直接返回
        if (data.length() >= length) {
            return data;
        }
        StringBuilder dataBuffer = new StringBuilder();
        //右拼接
        if (left) {
            dataBuffer.append(data);
            for (int i = 0; i < length - data.length(); i++) {
                dataBuffer.append(symbol);
            }
        }

        //左拼接
        if (!left) {
            for (int i = 0; i < length - data.length(); i++) {
                dataBuffer.append(symbol);
            }
            dataBuffer.append(data);
        }
        return dataBuffer.toString();
    }

    // 34进制字符集
    public static String toBase34(int number) {
        String base34Chars = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
        StringBuilder sb = new StringBuilder();

        while (number > 0) {
            int remainder = number % 34;
            sb.append(base34Chars.charAt(remainder));
            number /= 34;
        }
        return sb.reverse().toString();
    }
}
