no-comment 0.0.1

Remove rust-style line and block comments from a char iterator.
Documentation

Without Comments

Minimum Rust version: 1.31

Remove rust-style line and block 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.

Usage

Add this to your Cargo.toml:

[dependencies]
without-comments = "0.0.1"

main.rs:

fn main() {
        use std::fs::read_to_string;

        let without_comments = read_to_string("test.txt")
            .unwrap()
            .chars()
            .without_comments()
            .collect::<String>();

        println!("{}", without_comments);
}

test.txt:

This is text // this is a line comment
This is more text /* this is a block comment
/* this one is nested */ */
This is text again
/* If a block 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¶

Dependencies

This crate has no external dependencies