gpt4 book ai didi

java - 为什么在java中正则表达式的实现中使用魔数(Magic Number)?

转载 作者:行者123 更新时间:2023-11-30 11:24:09 25 4
gpt4 key购买 nike

Matcher类的构造函数源码:

Matcher(Pattern parent, CharSequence text) {
this.parentPattern = parent;
this.text = text;

// Allocate state storage
int parentGroupCount = Math.max(parent.capturingGroupCount, 10);
groups = new int[parentGroupCount * 2];
locals = new int[parent.localCount];

// Put fields into initial states
reset();
}

为什么我们不直接使用 parent.capturingGroupCount*2 作为组的长度?

最佳答案

这可能是为了更容易支持反向引用 (\0-\9) 而无需任何特殊情况。

关于java - 为什么在java中正则表达式的实现中使用魔数(Magic Number)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20811211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com