From 4d3ed4d73a6b8d82ecce2b1ff02916061377c739 Mon Sep 17 00:00:00 2001 From: Matthieu Jolimaitre Date: Mon, 23 Jun 2025 21:34:55 +0200 Subject: [PATCH] Ignore md separators. --- src/main.rs | 11 ++++++++--- test/out.txt | 4 ++++ test/run | 7 +++++++ test/source.txt | 18 ++++++++++-------- 4 files changed, 29 insertions(+), 11 deletions(-) create mode 100755 test/run diff --git a/src/main.rs b/src/main.rs index 4df1fde..fbd5f74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,10 @@ -use std::{env::args, fs}; +use std::{env, fs}; fn main() { - let file = args().nth(1).expect("Usage : boxon "); + let file = env::args().nth(1).expect("Usage : boxon "); let content = fs::read_to_string(&file).unwrap_or_else(|_| panic!("Could not read file '{file}'.")); let mut grid = Grid::from(content); - let count = grid.fix(); + let count = grid.fix(); println!("Fixed {count} characters."); let content: String = grid.into(); fs::write(&file, content).unwrap_or_else(|_| panic!("Could not write result to file '{file}'.")); @@ -34,6 +34,9 @@ impl Grid { let mut result = 0; let copy = self.clone(); for (y, line) in self.0.iter_mut().enumerate() { + if line == &vec!['-', '-', '-'] { + continue; + } for (x, character) in line.iter_mut().enumerate() { if let Some(cross) = copy.cross_at(x as i32, y as i32) { let new_char = match cross { @@ -207,6 +210,8 @@ fn connects(c: char) -> Cross { const F_: bool = false; const MM: bool = true; type Empt = (); + +#[repr(Rust, packed)] struct Cross( (Empt, bool, Empt), // (bool, bool, bool), // diff --git a/test/out.txt b/test/out.txt index 9f3cf9b..853e453 100644 --- a/test/out.txt +++ b/test/out.txt @@ -17,3 +17,7 @@ this is a normalized data table diagram. │ 1│ bob│ 19│ │ 2│ charlie│ 23│ └──┴────────┴───┘ + +--- + +Fin. \ No newline at end of file diff --git a/test/run b/test/run new file mode 100755 index 0000000..619a1a7 --- /dev/null +++ b/test/run @@ -0,0 +1,7 @@ +#!/usr/bin/bash +set -e +cd "$(dirname "$(realpath "$0")")" +cp source.txt out.txt + +cd .. +cargo run -- test/out.txt diff --git a/test/source.txt b/test/source.txt index a6132ea..5617c96 100644 --- a/test/source.txt +++ b/test/source.txt @@ -9,13 +9,15 @@ this is a normalized data table diagram. | 1|b@o.b| 1| | 2|c@r.l| 2| +--+-----+-------+ -+---------------+ -|USERS | -+--+--------+---+ -|id| name|age| -+--+--------+---+ -| 1| bob| 19| -| 2| charlie| 23| -+--+--------+---+ + +---------------+ + |USERS | + +--+--------+---+ + |id| name|age| + +--+--------+---+ + | 1| bob| 19| + | 2| charlie| 23| + +--+--------+---+ +--- +Fin.