From 1d25cbdd243ea2321fd0aaec3a915b51926e1109 Mon Sep 17 00:00:00 2001 From: Zjp <1215582715@qq.com> Date: Wed, 9 Nov 2022 11:12:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BC=98=E5=8C=96=E4=BA=86=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=BB=93=E6=9E=9C=E7=9A=84StringBuilder=E7=9A=84?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=95=BF=E5=BA=A6;=202.=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BA=86expression=E7=9A=84=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E6=93=8D=E4=BD=9C;=203.=20=E4=BC=98=E5=8C=96=E4=BA=86=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=BC=82=E5=B8=B8=E6=97=B6=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/core/text/PlaceholderParser.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/text/PlaceholderParser.java b/hutool-core/src/main/java/cn/hutool/core/text/PlaceholderParser.java index c01cd6116..2d0aef5b6 100644 --- a/hutool-core/src/main/java/cn/hutool/core/text/PlaceholderParser.java +++ b/hutool-core/src/main/java/cn/hutool/core/text/PlaceholderParser.java @@ -1,5 +1,6 @@ package cn.hutool.core.text; +import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.lang.Assert; import java.util.Objects; @@ -102,7 +103,7 @@ public class PlaceholderParser implements UnaryOperator { // 开始匹配 char[] src = text.toCharArray(); - final StringBuilder result = new StringBuilder(); + final StringBuilder result = new StringBuilder(src.length); StringBuilder expression = new StringBuilder(); while (openCursor > -1) { @@ -136,15 +137,14 @@ public class PlaceholderParser implements UnaryOperator { } } - // 未能找到结束符号,说明匹配结束 + // 未能找到结束符号,说明匹配异常 if (end == -1) { - result.append(src, openCursor, src.length - openCursor); - closeCursor = src.length; + throw new UtilException("\"{}\" 中字符下标 {} 处的开始符没有找到对应的结束符", text, openCursor); } // 找到结束符号,将开始到结束符号之间的字符串替换为指定表达式 else { result.append(processor.apply(expression.toString())); - expression = new StringBuilder(); + expression.setLength(0); // 完成当前占位符的处理匹配,寻找下一个 closeCursor = end + close.length(); }