mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
1. 优化了保存结果的StringBuilder的初始化长度;
2. 优化了expression的重置操作; 3. 优化了解析异常时的处理;
This commit is contained in:
parent
0eb1ecb1b7
commit
1d25cbdd24
@ -1,5 +1,6 @@
|
|||||||
package cn.hutool.core.text;
|
package cn.hutool.core.text;
|
||||||
|
|
||||||
|
import cn.hutool.core.exceptions.UtilException;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -102,7 +103,7 @@ public class PlaceholderParser implements UnaryOperator<String> {
|
|||||||
|
|
||||||
// 开始匹配
|
// 开始匹配
|
||||||
char[] src = text.toCharArray();
|
char[] src = text.toCharArray();
|
||||||
final StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder(src.length);
|
||||||
StringBuilder expression = new StringBuilder();
|
StringBuilder expression = new StringBuilder();
|
||||||
while (openCursor > -1) {
|
while (openCursor > -1) {
|
||||||
|
|
||||||
@ -136,15 +137,14 @@ public class PlaceholderParser implements UnaryOperator<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 未能找到结束符号,说明匹配结束
|
// 未能找到结束符号,说明匹配异常
|
||||||
if (end == -1) {
|
if (end == -1) {
|
||||||
result.append(src, openCursor, src.length - openCursor);
|
throw new UtilException("\"{}\" 中字符下标 {} 处的开始符没有找到对应的结束符", text, openCursor);
|
||||||
closeCursor = src.length;
|
|
||||||
}
|
}
|
||||||
// 找到结束符号,将开始到结束符号之间的字符串替换为指定表达式
|
// 找到结束符号,将开始到结束符号之间的字符串替换为指定表达式
|
||||||
else {
|
else {
|
||||||
result.append(processor.apply(expression.toString()));
|
result.append(processor.apply(expression.toString()));
|
||||||
expression = new StringBuilder();
|
expression.setLength(0);
|
||||||
// 完成当前占位符的处理匹配,寻找下一个
|
// 完成当前占位符的处理匹配,寻找下一个
|
||||||
closeCursor = end + close.length();
|
closeCursor = end + close.length();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user