数字革命 / jbdiff
基于JetBrains实现的差异库
1.2.2
2023-07-07 12:24 UTC
Requires
- php: >=8.1
Requires (Dev)
- digitalrevolution/accessorpair-constraint: ^2.1
- digitalrevolution/phpunit-file-coverage-inspection: ^2.0
- phpmd/phpmd: ^2.13
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.0
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.7
README
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);
使用ComparisonPolicy::IGNORE_WHITESPACES
比较策略
DEFAULT
:标准差异策略,将考虑空白字符差异。TRIM_WHITESPACES
:从差异中去除首尾空白字符。IGNORE_WHITESPACES
:从差异中去除所有空白字符差异。
示例
要运行示例页面,请启动
composer run example
页面将在http://localhost:8000/
上可用
关于我们
在123inkt(数字革命B.V.的一部分),每天都有超过50名开发专业人士致力于改进我们的内部ERP和我们的几个商店。你想加入我们吗?我们正在寻找开发者。