3 个版本
0.0.3 | 2020年4月7日 |
---|---|
0.0.2 | 2020年4月6日 |
0.0.1 | 2020年3月28日 |
在 文本处理 中排名 #837
每月下载量 4,530
用于 flex-rs
31KB
739 行
无注释
从 char
迭代器中移除注释。
此 crate 提供了 WithoutComments
迭代器和为所有 Iterator<Item=char>
实现的 IntoWithoutComments
trait,提供 without_comments
方法。支持 Rust 风格、C 风格、Python 风格和 Haskell 风格的行和块注释,计划提供自定义注释规范的方法。此 crate 旨在用于从文本中移除注释,而不是从代码中移除,因此,在 Rust 模式下,"\*"
仍会打开块注释,因为字符串字面量没有语义意义。
用法
将此添加到您的 Cargo.toml
[dependencies]
without-comments = "0.0.3"
main.rs
fn main() {
use std::fs::read_to_string;
use no_comment::{IntoWithoutComments as _, languages};
let without_comments = read_to_string("tests.txt")
.unwrap()
.chars()
.without_comments(languages::rust())
.collect::<String>();
println!("{}", without_comments);
}
test.txt
This is text // this is a (rust) line comment
This is more text /* this is a (rust) block comment
/* this one is nested */ */
This is text again
/* If a comment is left open, it keeps
going until the end.
输出
This is text
This is more text
This is text again
请注意,保留尾随空格和新行,显示空白,输出看起来像这样
This·is·text·¶
This·is·more·text·¶
This·is·text·again¶
依赖项
~0.4–0.8MB
~19K SLoC