15m30: protectCut嵌套编号+汉字数字(第X章第X节整串保护,X=一二三...十/0-9),切点>=短语起点回退到最外层第前,根治'第六章第3节'被劈; Java实测(反射jar逻辑)34页无劈编号
Auto Release / build (push) Successful in 4m13s

This commit is contained in:
youpaishidifu
2026-11-23 22:18:45 +08:00
parent 51a76b2441
commit 6408c32577
@@ -541,18 +541,16 @@ public class CustomScreenManager implements Listener {
* 让整段编号完整留页或完整翻页, 绝不被劈。 */ * 让整段编号完整留页或完整翻页, 绝不被劈。 */
static int protectCut(String s, int cut) { static int protectCut(String s, int cut) {
if (cut <= 0 || cut >= s.length()) return cut; if (cut <= 0 || cut >= s.length()) return cut;
// 在切点附近(前12字~后5字)找"第\s*\d+\s*[节章条款]"短语 // 15m30: 嵌套编号"第X章第X节"(X=汉字/阿拉伯数字)整串保护, 切点在短语内回退到最外层"第"前
int from = Math.max(0, cut - 12); int from = Math.max(0, cut - 12);
int to = Math.min(s.length(), cut + 5); int to = Math.min(s.length(), cut + 5);
String window = s.substring(from, to); String window = s.substring(from, to);
// 找 window 里所有短语匹配, 看切点是否劈在某短语内部 java.util.regex.Matcher m = java.util.regex.Pattern.compile("第\s*[0-9一二三四五六七八九十]+\s*[节章条款](\s*第\s*[0-9一二三四五六七八九十]+\s*[节章条款]){0,2}").matcher(window);
java.util.regex.Matcher m = java.util.regex.Pattern.compile("本\\s*\\d+\\s*[节章条款]").matcher(window);
while (m.find()) { while (m.find()) {
int phraseStart = from + m.start(); // "第"字位置 int phraseStart = from + m.start();
int phraseEnd = from + m.end(); // 短语末字(节/章/条/款)之后 int phraseEnd = from + m.end();
// 切点 cut 落在 (phraseStart, phraseEnd) 内 = 劈在短语内部 if (cut >= phraseStart && cut < phraseEnd) {
if (cut > phraseStart && cut < phraseEnd) { return Math.max(phraseStart - 1, cut - 12); // 回退到最外层"第"前, 整串编号翻页
return Math.max(phraseStart, cut - 12); // 回退到"第"前
} }
} }
return cut; return cut;