Skip to content

Commit 5ec185a

Browse files
committed
fix:修改调试输出 且 特殊处理开始和结束的换行符问题
1 parent 3091b33 commit 5ec185a

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

src/cvbManager.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ function applyExactReplace(strContent: string, op: ExactReplaceOperation): strin
571571
const errorMsg = `EXACT-REPLACE 失败\n` +
572572
`错误:\n${diagnosticMessage}`;
573573

574-
console.log(errorMsg);
574+
console.log(errorMsg + `\n表达式: ${regPattern}`);
575575
throw new Error(errorMsg);
576576
}
577577

@@ -593,7 +593,7 @@ function applyGlobalReplace(strContent: string, op: GlobalReplaceOperation) : st
593593
regPattern.lastIndex = 0;
594594
if (!regPattern.test(strContent)) {
595595
const errorMsg = `GLOBAL-REPLACE 失败:FILE:"${op.m_strFilePath}" 中未找到OLD_CONTENT: "${op.m_strOldContent}"`;
596-
console.log(errorMsg);
596+
console.log(errorMsg + `\n表达式: ${regPattern}`);
597597
throw new Error(errorMsg);
598598
}
599599
regPattern.lastIndex = 0;
@@ -646,19 +646,32 @@ function escapeRegExp(str: string) : string
646646
}
647647

648648
function normalizeLineWhitespace(anchor: string): string {
649-
return anchor.split('\n')
650-
.map(line => {
651-
line = line.trim();
652-
if (line.length > 0){
653-
line = line.replace(/\s+/g, '\\s*');
654-
line = `\\s*${line}\\s*`;
655-
}
656-
else{
657-
line = "\\s*";
658-
}
659-
return line; // 保留行首和行尾的空白字符处理
660-
})
661-
.join('\n'); // 行与行之间允许有空白字符(空格、换行符等)
649+
// 按行拆分后对每行做空白归一化处理
650+
let aszNormalized_Arr: string[] = anchor.split('\n')
651+
.map((szLine_Str: string, unIndex_Uint: number, aszArr_Arr: string[]) => {
652+
szLine_Str = szLine_Str.trim();
653+
if (szLine_Str.length > 0) {
654+
// 将行内连续空白替换为 \s*
655+
szLine_Str = szLine_Str.replace(/\s+/g, '\\s*');
656+
// 在每行前后各增加一个 \s*
657+
szLine_Str = `\\s*${szLine_Str}\\s*`;
658+
}
659+
else {
660+
// 空行处理:直接使用 \s*
661+
szLine_Str = "\\s*";
662+
}
663+
return szLine_Str;
664+
});
665+
666+
// 去除整体结果中最开头和最末尾多余的 \s*
667+
if (aszNormalized_Arr.length > 0) {
668+
// 第1行:移除行首的 \s*
669+
aszNormalized_Arr[0] = aszNormalized_Arr[0].replace(/^\\s\*/, '');
670+
// 最后一行:移除行尾的 \s*
671+
aszNormalized_Arr[aszNormalized_Arr.length - 1] = aszNormalized_Arr[aszNormalized_Arr.length - 1].replace(/\\s\*$/, '');
672+
}
673+
674+
return aszNormalized_Arr.join('\n');
662675
}
663676

664677
function filePathNormalize(strRawPath: string) : string

0 commit comments

Comments
 (0)