15m29b: protectCut改正则识别'第N节/章/条/款'整短语(前12后5窗口),切点在短语内部才回退,根治'第六章第3节'被劈; 修复单反斜杠Java非法转义
Auto Release / build (push) Successful in 4m12s
Auto Release / build (push) Successful in 4m12s
This commit is contained in:
@@ -536,21 +536,24 @@ public class CustomScreenManager implements Listener {
|
||||
* 15m27 bug: 原触发要"末字=数字/第 且 下页首字=节/章/条/款"同时成立才回退,
|
||||
* 实际渲染"节"被甩到下一页时 Java 切点处 lastChar 常是普通汉字(非数字), 触发不中。
|
||||
* 放宽: 只要 末字是数字/"第"(编号主体留页) 或 下页首字是"节/章/条/款"(编号后缀甩页), 一律回退。 */
|
||||
/** 15m29 编号保护: 用正则识别"第N节/章/条/款"整短语(第+数字+后缀, 间可有空格),
|
||||
* 切点若落在短语内部(把"第 3 节"劈成"第"+"3 节"或"第 3"+"节")→ 回退到短语起点"第"前,
|
||||
* 让整段编号完整留页或完整翻页, 绝不被劈。 */
|
||||
static int protectCut(String s, int cut) {
|
||||
if (cut <= 0 || cut >= s.length()) return cut;
|
||||
char lastChar = s.charAt(cut - 1);
|
||||
char nextChar = s.charAt(cut);
|
||||
boolean pageEndIsNumOrDi = Character.isDigit(lastChar) || lastChar == '第';
|
||||
boolean nextIsSuffix = (nextChar == '节' || nextChar == '章' || nextChar == '条' || nextChar == '款');
|
||||
if (pageEndIsNumOrDi || nextIsSuffix) {
|
||||
// 往回找编号起点: 先回数字串, 跳过空白, 再回"第"字, 把整段编号留到下一页
|
||||
int rollback = cut;
|
||||
while (rollback > 0 && Character.isDigit(s.charAt(rollback - 1))) rollback--;
|
||||
while (rollback > 0 && s.charAt(rollback - 1) == ' ') rollback--;
|
||||
if (rollback > 0 && s.charAt(rollback - 1) == '第') rollback--;
|
||||
int maxRollback = cut - 10;
|
||||
if (rollback < maxRollback) rollback = maxRollback;
|
||||
if (rollback < cut) return rollback;
|
||||
// 在切点附近(前12字~后5字)找"第\s*\d+\s*[节章条款]"短语
|
||||
int from = Math.max(0, cut - 12);
|
||||
int to = Math.min(s.length(), cut + 5);
|
||||
String window = s.substring(from, to);
|
||||
// 找 window 里所有短语匹配, 看切点是否劈在某短语内部
|
||||
java.util.regex.Matcher m = java.util.regex.Pattern.compile("本\\s*\\d+\\s*[节章条款]").matcher(window);
|
||||
while (m.find()) {
|
||||
int phraseStart = from + m.start(); // "第"字位置
|
||||
int phraseEnd = from + m.end(); // 短语末字(节/章/条/款)之后
|
||||
// 切点 cut 落在 (phraseStart, phraseEnd) 内 = 劈在短语内部
|
||||
if (cut > phraseStart && cut < phraseEnd) {
|
||||
return Math.max(phraseStart, cut - 12); // 回退到"第"前
|
||||
}
|
||||
}
|
||||
return cut;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user