Class PlaceholderParser

java.lang.Object
org.miaixz.bus.core.text.placeholder.PlaceholderParser
All Implemented Interfaces:
Function<String,String>, UnaryOperator<String>

public class PlaceholderParser extends Object implements UnaryOperator<String>
一个简单的占位符解析器。给定占位符的左右边界符号以及转义符, 将允许把一段字符串中的占位符解析并替换为指定内容,支持指定转义符对边界符号进行转义。
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • PlaceholderParser

      public PlaceholderParser(UnaryOperator<String> processor, String prefix, String suffix)
      创建一个占位符解析器,默认转义符为"\"
      Parameters:
      processor - 占位符处理器
      prefix - 占位符开始符号,不允许为空
      suffix - 占位符结束符号,不允许为空
    • PlaceholderParser

      public PlaceholderParser(UnaryOperator<String> processor, String prefix, String suffix, char escape)
      创建一个占位符解析器
      Parameters:
      processor - 占位符处理器
      prefix - 占位符开始符号,不允许为空
      suffix - 占位符结束符号,不允许为空
      escape - 转义符
  • Method Details

    • apply

      public String apply(String text)
      解析并替换字符串中的占位符
      Specified by:
      apply in interface Function<String,String>
      Parameters:
      text - 待解析的字符串
      Returns:
      处理后的字符串