aardio 文档

textkit.patch:精确补丁

literal-only / unique / atomic / same-original。本库是文件编辑工具使用的底层补丁引擎,只处理字符串、不读写文件;通过工具编辑文件时不需要直接调用。原文包含补丁标记行、需要行号或明确批量匹配时,用 textkit.editor。

最小调用

import textkit.patch;

var text = 'old();\r\nkeep();\n';
var patchText = /******
<<<<<<< SEARCH
old();
=======
new();
>>>>>>> REPLACE
******/;

var result,err,info = textkit.patch.apply(text,patchText,{previewMaxBytes=0});
if(result === null) return {error=err;info=info};
print(result); // 'new();\r\nkeep();\n'

必须记住

返回与恢复

apply(text,patchText[,options]):

options.previewMaxBytes 默认 1024,范围 0..4096,0 关闭文本回显;changePreview=false 关闭成功预览。预览最多 4 处、定位最多 6 处。字节预算只限制回显,不限制实际编辑,也不包含固定有界元数据。*Bytes 都是字节预算或统计,不是字符位置。

此库只处理字符串,不负责文件 BOM、备份、编译或写入;文件工具负责这些步骤。

textkit 主库

Markdown 格式