From c9a33c75de64dccb14cd5cb33d389f2a48316058 Mon Sep 17 00:00:00 2001 From: Cass Fridkin Date: Tue, 29 Oct 2024 16:09:09 -0600 Subject: [PATCH] Deal with CRLF on windows --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/2016/08.rs | 37 +++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 312fdc8..9b70d75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,7 @@ dependencies = [ "itoa", "md-5", "memchr", + "newline-converter", "nohash-hasher", "paste", "pathsep", @@ -546,6 +547,15 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "newline-converter" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b6b097ecb1cbfed438542d16e84fd7ad9b0c76c8a65b7f9039212a3d14dc7f" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -831,6 +841,12 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "utf8parse" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 1dd916d..b10749c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ memchr = "2.7.4" clap = { version = "4.5.20", features = ["derive"] } clap-stdin = "0.5.1" pathsep = "0.1.1" +newline-converter = "0.3.0" [target.'cfg(windows)'.dependencies] md-5 = "0.10.6" diff --git a/src/2016/08.rs b/src/2016/08.rs index 9518bfc..8e31d9d 100644 --- a/src/2016/08.rs +++ b/src/2016/08.rs @@ -1,9 +1,8 @@ -use std::{ - fmt::{self, Display, Formatter, Write}, - str::FromStr, -}; +use std::fmt::{self, Display, Formatter, Write}; +use std::str::FromStr; use eyre::{bail, eyre, Report, Result}; +use newline_converter::AsRefStrExt; use rayon::prelude::*; use winnow::{ ascii::dec_uint, @@ -159,24 +158,26 @@ impl Screen { impl Screen<5, 6> { fn letter(&self) -> Result { macro_rules! LETTERS { - ($($letter:ident),+) => {$( - const $letter: &str = include_str!(concat!( - env!("CARGO_MANIFEST_DIR"), - ::pathsep::path_separator!(), - "fixtures", - ::pathsep::path_separator!(), - "2016", - ::pathsep::path_separator!(), - "08", - ::pathsep::path_separator!(), - stringify!($letter) - )); - )+}; + ($($letter:ident),+) => { + $( + const $letter: &str = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + ::pathsep::path_separator!(), + "fixtures", + ::pathsep::path_separator!(), + "2016", + ::pathsep::path_separator!(), + "08", + ::pathsep::path_separator!(), + stringify!($letter) + )); + )+ + }; } LETTERS!(A, B, C, D, E, F, I, J, K, L, O, P, R, S, U, Y, Z); - match self.to_string().as_str() { + match self.to_string().to_unix().as_ref() { A => Ok('A'), B => Ok('B'), C => Ok('C'),