1 Star 3 Fork 63

1024chen / Rust代码和资源汇总

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cleanup.rs 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
shirdon 提交于 2019-07-21 13:37 . commit
// 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<String>) -> Vec<String> {
let mut fixed_lines: Vec<String> = 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<String> = 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");
}
Rust
1
https://gitee.com/chen0adapter/awesome-rust.git
git@gitee.com:chen0adapter/awesome-rust.git
chen0adapter
awesome-rust
Rust代码和资源汇总
master

搜索帮助