From dc461b9fceae562498a5bfde9da5342932a0c024 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 11 Apr 2023 14:12:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E6=88=AA=E5=8F=96BUG=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/discriminate/VoiceDiscriminateResult.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/discriminate/VoiceDiscriminateResult.java b/src/main/java/club/joylink/rtss/simulation/cbtc/discriminate/VoiceDiscriminateResult.java index d64d1309c..c296485b9 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/discriminate/VoiceDiscriminateResult.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/discriminate/VoiceDiscriminateResult.java @@ -118,19 +118,21 @@ public class VoiceDiscriminateResult { public int[] getPinYinGroupAtOriginStartAndEndIndex(int index) { String group = getGroup(index); // 获取到group int[] indexArr = new int[2]; // 索引数组 - int readIndex = 0; + // 读取起始位置、group长度、读取结束位置 + int groupLen = group.length(), readIndex = 0, endIndex = 0; String pinYin = null; for (int i = 0, len = contentPinYinArr.length; i < len; i ++) { pinYin = contentPinYinArr[i]; - if (Objects.equals(group.substring(readIndex, readIndex + pinYin.length()), pinYin)) { // 字符一致 + endIndex = readIndex + pinYin.length(); + if (groupLen >= endIndex && Objects.equals(group.substring(readIndex, endIndex), pinYin)) { // 字符一致 if (readIndex == 0) { // 如果是0代表刚开始匹配,记录开始索引 indexArr[0] = i; } - readIndex = readIndex + pinYin.length(); + readIndex = endIndex; } else { // 字符不一致,重新匹配位置 readIndex = 0; } - if (readIndex == group.length()) { // 结束位置 + if (readIndex == groupLen) { // 结束位置 indexArr[1] = i; break; }