#diff #parse #nom #parser

patch

解析统一diff格式的补丁

9个版本 (重大更改)

0.7.0 2022年12月28日
0.6.0 2022年1月12日
0.5.0 2019年2月13日
0.4.2 2017年9月7日
0.4.1 2016年11月25日

#736解析器实现

Download history 2056/week @ 2024-03-14 2035/week @ 2024-03-21 1851/week @ 2024-03-28 1960/week @ 2024-04-04 1904/week @ 2024-04-11 2104/week @ 2024-04-18 1863/week @ 2024-04-25 2287/week @ 2024-05-02 2568/week @ 2024-05-09 2144/week @ 2024-05-16 1986/week @ 2024-05-23 3137/week @ 2024-05-30 2159/week @ 2024-06-06 1660/week @ 2024-06-13 1761/week @ 2024-06-20 1410/week @ 2024-06-27

7,366 每月下载量
用于 12 个crate(10个直接使用)

MIT 协议

36KB
697

补丁

Checks Crates.io Badge docs.rs Lines of Code

Rust crate,用于解析和生成统一格式的补丁文件。

解析器试图足够宽容以兼容由git等程序生成的diff。它通过忽略这些程序在diff中提供的附加代码上下文和信息来实现这一点。

请参阅 文档 获取更多信息及示例。


lib.rs:

解析和生成统一格式的补丁文件(diff)。

格式尚未完全定义,但Guido van Rossum等人已经完成了这项工作来找出细节。

解析器试图足够宽容以兼容由git等程序生成的diff。它通过忽略这些程序在diff中提供的附加代码上下文和信息来实现这一点。

示例

// Make sure you add the `patch` crate to the `[dependencies]` key of your Cargo.toml file.
use patch::Patch;

let sample = "\
--- before.py
+++ path/to/after.py
@@ -1,4 +1,4 @@
-bacon
-eggs
-ham
+python
+eggy
+hamster
 guido\n";

let patch = Patch::from_single(sample)?;
assert_eq!(&patch.old.path, "before.py");
assert_eq!(&patch.new.path, "path/to/after.py");

// Print out the parsed patch file in its Rust representation
println!("{:#?}", patch);

// Print out the parsed patch file in the Unified Format. For input that was originally in the
// Unified Format, this will produce output identical to that original input.
println!("{}", patch); // use format!("{}\n", patch) to get this as a String

依赖关系

~2.5MB
~40K SLoC