• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript diff-match-patch.diff_match_patch类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中diff-match-patch.diff_match_patch的典型用法代码示例。如果您正苦于以下问题:TypeScript diff_match_patch类的具体用法?TypeScript diff_match_patch怎么用?TypeScript diff_match_patch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了diff_match_patch类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: testDiffMainEach

function testDiffMainEach() {
    const oldValue = "hello world, how are you?";
    const newValue = "hello again world. how have you been?";

    const diffEngine = new DiffMatchPatch.diff_match_patch();
    const diffs = diffEngine.diff_main(oldValue, newValue);
    diffEngine.diff_cleanupSemantic(diffs);

    let changes = "";
    let pattern = "";

    diffs.forEach((diff) => {
        const operation = diff[0]; // Operation (insert, delete, equal)
        const text = diff[1]; // Text of change

        switch (operation) {
            case DiffMatchPatch.DIFF_INSERT:
                pattern += "I";
                break;
            case DiffMatchPatch.DIFF_DELETE:
                pattern += "D";
                break;
            case DiffMatchPatch.DIFF_EQUAL:
                pattern += "E";
                break;
        }

        changes += text;
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:30,代码来源:diff-match-patch-tests.ts


示例2: testPatchMake

function testPatchMake() {
    const text1 = 'The quick brown fox jumps over the lazy dog.';
    const text2 = 'That quick brown fox jumped over a lazy dog.';
    let expectedPatch = '@@ -1,8 +1,7 @@\n Th\n-at\n+e\n  qui\n@@ -21,17 +21,18 @@\n jump\n-ed\n+s\n  over \n-a\n+the\n  laz\n';
    let patches = dmp.patch_make(text2, text1);
    assertEquals(expectedPatch, dmp.patch_toText(patches));

    // Method 1
    expectedPatch = '@@ -1,11 +1,12 @@\n Th\n-e\n+at\n  quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n';
    patches = dmp.patch_make(text1, text2);
    assertEquals(expectedPatch, dmp.patch_toText(patches));

    // Method 2
    const diffs = dmp.diff_main(text1, text2, false);
    patches = dmp.patch_make(diffs);
    assertEquals(expectedPatch, dmp.patch_toText(patches));

    // Method 3
    patches = dmp.patch_make(text1, diffs);
    assertEquals(expectedPatch, dmp.patch_toText(patches));

    // Method 4
    patches = dmp.patch_make(text1, text2, diffs);
    assertEquals(expectedPatch, dmp.patch_toText(patches));
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:25,代码来源:diff-match-patch-tests.ts


示例3: testDiffMain

function testDiffMain() {
    assertEquivalent([], dmp.diff_main('', '', false));

    dmp.Diff_Timeout = 0;
    // Simple cases.
    assertEquivalent([[DIFF_DELETE, 'a'], [DIFF_INSERT, 'b']], dmp.diff_main('a', 'b', false));
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:7,代码来源:diff-match-patch-tests.ts


示例4: testPatchApply

function testPatchApply() {
    dmp.Match_Distance = 1000;
    dmp.Match_Threshold = 0.5;
    dmp.Patch_DeleteThreshold = 0.5;
    const patches = dmp.patch_make('The quick brown fox jumps over the lazy dog.', 'That quick brown fox jumped over a lazy dog.');
    const results = dmp.patch_apply(patches, 'The quick brown fox jumps over the lazy dog.');
    assertEquivalent(['That quick brown fox jumped over a lazy dog.', [true, true]], results);
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:8,代码来源:diff-match-patch-tests.ts


示例5: testDiffHalfMatch

function testDiffHalfMatch() {
    dmp.Diff_Timeout = 1;

    assertEquals(null, dmp.diff_halfMatch_('1234567890', 'abcdef'));

    assertEquivalent(['12', '90', 'a', 'z', '345678'], dmp.diff_halfMatch_('1234567890', 'a345678z'));

    assertEquivalent(['12123', '123121', 'a', 'z', '1234123451234'], dmp.diff_halfMatch_('121231234123451234123121', 'a1234123451234z'));
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:9,代码来源:diff-match-patch-tests.ts


示例6: testDiffDelta

function testDiffDelta() {
    const diffs: DiffMatchPatch.Diff[] =
      [[DIFF_EQUAL, 'jump'], [DIFF_DELETE, 's'], [DIFF_INSERT, 'ed'], [DIFF_EQUAL, ' over '], [DIFF_DELETE, 'the'], [DIFF_INSERT, 'a'], [DIFF_EQUAL, ' lazy'], [DIFF_INSERT, 'old dog']];
    const text1 = dmp.diff_text1(diffs);
    assertEquals('jumps over the lazy', text1);

    const delta = dmp.diff_toDelta(diffs);
    assertEquals('=4\t-1\t+ed\t=6\t-3\t+a\t=5\t+old dog', delta);

    assertEquivalent(diffs, dmp.diff_fromDelta(text1, delta));
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:11,代码来源:diff-match-patch-tests.ts


示例7: testPatchSplitMax

function testPatchSplitMax() {
    const patches = dmp.patch_make('abcdefghijklmnopqrstuvwxyz01234567890', 'XabXcdXefXghXijXklXmnXopXqrXstXuvXwxXyzX01X23X45X67X89X0');
    dmp.patch_splitMax(patches);
    assertEquals(
        [
            '@@ -1,32 +1,46 @@\n',
            '+X\n ab\n+X\n cd\n+X\n ef\n+X\n gh\n+X\n ij\n+X\n kl\n+X\n mn\n+X\n op\n+X\n qr\n+X\n st\n+X\nuv\n+X\n wx\n+X\n yz\n+X\n 012345\n',
            '@@ -25,13 +39,18 @@',
            '\n zX01\n+X\n 23\n+X\n 45\n+X\n 67\n+X\n 89\n+X\n 0\n'
        ].join(''),
        dmp.patch_toText(patches));
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:12,代码来源:diff-match-patch-tests.ts


示例8: testMatchAlphabet

function testMatchAlphabet() {
    const expected: {[char: string]: number} = {};
    expected['a'] = 4;
    expected['b'] = 2;
    expected['c'] = 1;
    assertEquivalent(expected, dmp.match_alphabet_('abc'));
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:7,代码来源:diff-match-patch-tests.ts


示例9: testDiffCleanupEfficiency

function testDiffCleanupEfficiency() {
    dmp.Diff_EditCost = 4;

    const diffs: DiffMatchPatch.Diff[] = [[DIFF_DELETE, 'ab'], [DIFF_INSERT, '12'], [DIFF_EQUAL, 'wxyz'], [DIFF_DELETE, 'cd'], [DIFF_INSERT, '34']];
    dmp.diff_cleanupEfficiency(diffs);
    assertEquivalent([[DIFF_DELETE, 'ab'], [DIFF_INSERT, '12'], [DIFF_EQUAL, 'wxyz'], [DIFF_DELETE, 'cd'], [DIFF_INSERT, '34']], diffs);
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:7,代码来源:diff-match-patch-tests.ts


示例10: processResults

	protected processResults(output: string): TextEdit[] {
		const diffs: Diff[] = this.differ.diff_main(this.originalText, output);
		const edits: TextEdit[] = [];
		// VSCode wants TextEdits on the original document
		// this means position only gets moved for DIFF_EQUAL and DIFF_DELETE
		// as insert is new and doesn't have a position in the original
		let position = 0;
		for (let diff of diffs) {
			const [num, str] = diff;
			const startPos = this.document.positionAt(position);

			switch (num) {
				case DIFF_DELETE:
					edits.push({
						range: {
							start: startPos,
							end: this.document.positionAt(position + str.length),
						},
						newText: '',
					});
					position += str.length;
					break;
				case DIFF_INSERT:
					edits.push({
						range: { start: startPos, end: startPos },
						newText: str,
					});
					break;
				case DIFF_EQUAL:
					position += str.length;
					break;
			}

			// If we have a range we are doing a selection format. Thus,
			// only apply patches that start within the selected range
			if (this.range && num !== DIFF_EQUAL && !this.checkPositionInRange(startPos)) {
				edits.pop();
			}
		}

		return edits;
	}
开发者ID:rubyide,项目名称:vscode-ruby,代码行数:42,代码来源:BaseFormatter.ts



注:本文中的diff-match-patch.diff_match_patch类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript diff-sequences.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript diff.diffLines函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap