基于JetBrains实现的差异库

1.2.2 2023-07-07 12:24 UTC

This package is auto-updated.

Last update: 2024-09-03 14:50:49 UTC


README

Minimum PHP Version PHPStan codecov Build Status

JBDiff

一个基于JetBrains强大IDE差异实现的跨行差异计算库。
https://github.com/JetBrains/intellij-community/tree/master/platform/util/diff/src/com/intellij/diff

安装

composer require digitalrevolution/jbdiff

使用

$textBefore:

switch ($strategy) {
    case RateLimiterConfig::FIXED_WINDOW:
        return new FixedWindow($this->redisService->getConnection(), $config);
    case RateLimiterConfig::SLIDING_WINDOW:
        return new SlidingWindow($this->redisService->getConnection(), $config);
    default:
        throw new RuntimeException('Invalid Strategy name.', RuntimeException::UNKNOWN);
}

$textAfter:

return match ($strategy) {
    RateLimiterConfig::FIXED_WINDOW   => new FixedWindow($this->redisService->getConnection(), $config),
    RateLimiterConfig::SLIDING_WINDOW => new SlidingWindow($this->redisService->getConnection(), $config),
    default                           => throw new RuntimeException('Invalid Strategy name.'),
};

创建差异

use DR\JBDiff\ComparisonPolicy;
use DR\JBDiff\JBDiff;

// line block will contain all the information to partition the strings in removed, unchanged and added parts.
$lineBlocks = (new JBDiff())->compare($textBefore, $textAfter, ComparisonPolicy::DEFAULT);

// to iterate over the string parts
$iterator = new LineBlockTextIterator($textBefore, $textAfter, $lineBlocks);

$iterator格式化为HTML: docs/example-default.png

使用ComparisonPolicy::IGNORE_WHITESPACES docs/example-ignore-whitespace.png

比较策略

  • DEFAULT:标准差异策略,将考虑空白字符差异。
  • TRIM_WHITESPACES:从差异中去除首尾空白字符。
  • IGNORE_WHITESPACES:从差异中去除所有空白字符差异。

示例

要运行示例页面,请启动

composer run example

页面将在http://localhost:8000/上可用

docs/example-example.png

关于我们

在123inkt(数字革命B.V.的一部分),每天都有超过50名开发专业人士致力于改进我们的内部ERP和我们的几个商店。你想加入我们吗?我们正在寻找开发者