/**
 * bobotuan.com Inc.
 * Copyright (c) 2004-2020 All Rights Reserved.
 */
package com.qs.mp.common.utils;


import java.text.MessageFormat;

/**
 *
 *
 * @author chunping.zhongcp
 * @version $Id: MessageHelper.java, v 0.1 2020/5/22 chunping.zhongcp Exp $
 */
public class MessageHelper {


    public MessageHelper() {
    }

    public static String formatMsg(String msgTemplate, Object... positionValues) {
        try {
            return MessageFormat.format(msgTemplate, positionValues);
        } catch (Exception var5) {
            StringBuilder buf = new StringBuilder("资源信息占位符替换异常，占位符参数信息：");

            for (int i = 0; i < positionValues.length; ++i) {
                buf.append(" arg[" + i + "]=" + positionValues[i]);
            }

            return msgTemplate;
        }
    }

    public static String escape(String value) {
        if (value == null) {
            return null;
        } else {
            StringBuilder sb = new StringBuilder(value.length());
            int i = 0;

            for (int n = value.length(); i < n; ++i) {
                char source = value.charAt(i);
                switch (source) {
                    case '\n':
                        sb.append("%0A");
                        break;
                    case '\r':
                        sb.append("%0D");
                        break;
                    case '(':
                        sb.append("%28");
                        break;
                    case ')':
                        sb.append("%29");
                        break;
                    case ',':
                        sb.append("%2C");
                        break;
                    case '[':
                        sb.append("%5B");
                        break;
                    case ']':
                        sb.append("%5D");
                        break;
                    default:
                        sb.append(source);
                }
            }

            return sb.toString();
        }
    }
}
