From 24aee1b0291da4d6e27df247ee589974cb8f3a19 Mon Sep 17 00:00:00 2001 From: 132ikl <132@ikl.sh> Date: Tue, 5 Nov 2024 03:39:08 -0500 Subject: [PATCH] Switch to unicase's to_folded_case (#14255) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Switch `to_folded_case` to a proper case fold instead of `str::to_lowercase` now that unicase exposes its `to_folded_case` method. Rel: #10884, https://github.com/seanmonstar/unicase/issues/61 # User-Facing Changes Case insensitive sorts now do proper case folding. Old behavior: ```nushell [dreißig DREISSIG] | sort -i # => ╭───┬──────────╮ # => │ 0 │ DREISSIG │ # => │ 1 │ dreißig │ # => ╰───┴──────────╯ ``` New behavior: ```nushell [dreißig DREISSIG] | sort -i # => ╭───┬──────────╮ # => │ 0 │ dreißig │ # => │ 1 │ DREISSIG │ # => ╰───┴──────────╯ ``` --- crates/nu-utils/src/casing.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/crates/nu-utils/src/casing.rs b/crates/nu-utils/src/casing.rs index 6d22d6860b939..5ce15eacb5482 100644 --- a/crates/nu-utils/src/casing.rs +++ b/crates/nu-utils/src/casing.rs @@ -9,11 +9,6 @@ pub trait IgnoreCaseExt { /// language-invariant and consistent. Case folded text should be used /// solely for processing and generally should not be stored or displayed. /// - /// Note: this method might only do [`str::to_lowercase`] instead of a - /// full case fold, depending on how Nu is compiled. You should still - /// prefer using this method for generating case-insensitive strings, - /// though, as it expresses intent much better than `to_lowercase`. - /// /// [case folded]: fn to_folded_case(&self) -> String; @@ -40,9 +35,7 @@ pub trait IgnoreCaseExt { impl IgnoreCaseExt for str { fn to_folded_case(&self) -> String { - // we only do to_lowercase, as unicase doesn't expose its case fold yet - // (seanmonstar/unicase#61) and we don't want to pull in another table - self.to_lowercase() + UniCase::new(self).to_folded_case() } fn eq_ignore_case(&self, other: &str) -> bool {