diff --git a/.gitattributes b/.gitattributes index adff53c..e69de29 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +0,0 @@ -cleanup.py linguist-vendored diff --git a/.gitignore b/.gitignore index 1db65aa..b3c5812 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea/ Cargo.lock target/ +cleanup +cleanup.exe \ No newline at end of file diff --git a/cleanup.py b/cleanup.py deleted file mode 100644 index 1b769c3..0000000 --- a/cleanup.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Cleans up `README.md`. -""" - -import codecs - - -def fix_dashes(lines): - """ - """ - - fixed_lines = [] - - # Distinguish between the prologue and the content. - within_content = False - - # Iterate over the awesome lines. - for line in lines: - - # The current line is within the content. - if within_content: - - # Adjust the dash. - fixed_lines.append(line.replace(u' - ', u' — ')) - # - # The current line is within the prologue. - else: - # The prologue has ended. - if line.startswith(u'## Applications'): - within_content = True - - # Leave the current line unmodified. - fixed_lines.append(line) - - return fixed_lines - -# end def fix_dashes - - -# Read the awesome file. -with codecs.open('README.md', encoding='utf8') as awesome_file: - awesome_lines = awesome_file.readlines() - -# Fix the dashes. -awesome_lines = fix_dashes(awesome_lines) - -# Write the awesome file. -with codecs.open('README.md', 'wb', encoding='utf8') as awesome_file: - awesome_file.writelines(awesome_lines) diff --git a/cleanup.rs b/cleanup.rs new file mode 100644 index 0000000..75f76b0 --- /dev/null +++ b/cleanup.rs @@ -0,0 +1,44 @@ +// Cleans up `README.md` +// Usage: rustc cleanup.rs && ./cleanup + +use std::fs; +use std::fs::File; +use std::io::Read; + +fn fix_dashes(lines: Vec) -> Vec { + let mut fixed_lines: Vec = Vec::with_capacity(lines.len()); + + let mut within_content = false; + + for line in lines { + if within_content { + fixed_lines.push(line.replace(" - ", " — ")); + } else { + if line.starts_with("## Applications") { + within_content = true; + } + + fixed_lines.push(line.to_string()); + } + } + + return fixed_lines; +} + +fn main() { + // Read the awesome file. + let mut file = File::open("README.md").expect("Failed to read the file"); + + let mut contents = String::new(); + file.read_to_string(&mut contents) + .expect("Failed to read file contents"); + + // Split contents into lines. + let lines: Vec = contents.lines().map(|l| l.to_string()).collect(); + + // Fix the dashes. + let fixed_contents = fix_dashes(lines); + + // Write the awesome file. + fs::write("README.md", fixed_contents.join("\n").as_bytes()).expect("Failed to write to the file"); +} diff --git a/dummy.rs b/dummy.rs deleted file mode 100644 index 2e6e59f..0000000 --- a/dummy.rs +++ /dev/null @@ -1,4 +0,0 @@ -// A dummy file to give the repository a Rust flavor. -fn main() { - println!("Hello world!"); -}