| Crates.io | no-comment |
| lib.rs | no-comment |
| version | 0.0.3 |
| created_at | 2020-03-28 09:54:07.133434+00 |
| updated_at | 2020-04-07 09:13:58.702584+00 |
| description | Remove rust-style line and block comments from a char iterator. |
| homepage | https://crates.io/crates/no-comment |
| repository | https://github.com/gorilskij/no-comment |
| max_upload_size | |
| id | 223767 |
| size | 32,699 |
Remove comments from a char iterator.
This crate provides the WithoutComments iterator and the IntoWithoutComments trait implemented for
all Iterator<Item=char> providing the without_comments method. Comment specifications are available for
rust-style, c-style, python-style, and haskell-style line and block comments, a way to specify custom
comment specifications is planned. This crate is intended to be used for removing comments from text,
not from code, for this reason, "\*" will still open a block comment in rust mode because string literals
have no semantic significance.
Add this to your Cargo.toml:
[dependencies]
without-comments = "0.0.2"
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.
output:
This is text
This is more text
This is text again
Note that trailing spaces and newlines are preserved, showing whitespace the output looks like this:
This·is·text·¶
This·is·more·text·¶
This·is·text·again¶