yangys
2024-03-31 2969df3e404db3cd116f27db1495e523ce05bf86
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.qianwen.core.tool.utils;
 
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/utils/StringFormatUtil.class */
public class StringFormatUtil {
    private static final Pattern pattern = Pattern.compile("\\{(.*?)\\}");
    private static Matcher matcher;
 
    private StringFormatUtil() {
    }
 
    public static String format(String sourStr, Map<String, Object> param) {
        String tagerStr = sourStr;
        if (param == null) {
            return tagerStr;
        }
        try {
            matcher = pattern.matcher(tagerStr);
            while (matcher.find()) {
                String key = matcher.group();
                String keyclone = key.substring(1, key.length() - 1).trim();
                Object value = param.get(keyclone);
                if (value != null) {
                    tagerStr = tagerStr.replace(key, value.toString());
                }
            }
            return tagerStr;
        } catch (Exception e) {
            return null;
        }
    }
}