Skip to content

Commit

Permalink
Switch to unicase's to_folded_case (nushell#14255)
Browse files Browse the repository at this point in the history
# 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: nushell#10884, seanmonstar/unicase#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 │
# => ╰───┴──────────╯
```
  • Loading branch information
132ikl authored and NotTheDr01ds committed Nov 8, 2024
1 parent fc52b9a commit 24aee1b
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions crates/nu-utils/src/casing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]: <https://unicode.org/faq/casemap_charprop.html#2>
fn to_folded_case(&self) -> String;

Expand All @@ -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 {
Expand Down

0 comments on commit 24aee1b

Please sign in to comment.