1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
SPDX-License-Identifier: MIT OR Apache-2.0
SPDX-FileCopyrightText: © 2023-2026 Bruce D'Arcus and Citum contributors
*/
use super::Locale;
impl Locale {
/// Strip leading articles from a string for sorting.
///
/// Uses locale-specific articles (e.g., "the", "a", "an" for English;
/// "der", "die", "das" for German). Falls back to English articles
/// if no locale-specific articles are defined.
pub fn strip_sort_articles<'a>(&self, s: &'a str) -> &'a str {
let s = s.trim();
// Default English articles
const DEFAULT_ARTICLES: &[&str] = &["the", "a", "an"];
if self.sort_articles.is_empty() {
// Use default English articles
for article in DEFAULT_ARTICLES {
let prefix = format!("{} ", article);
if s.to_lowercase().starts_with(&prefix) {
#[allow(
clippy::string_slice,
reason = "prefix is derived from ASCII article"
)]
return &s[prefix.len()..];
}
}
} else {
// Use locale-specific articles
for article in &self.sort_articles {
let prefix = format!("{} ", article);
if s.to_lowercase().starts_with(&prefix) {
#[allow(
clippy::string_slice,
reason = "prefix is derived from a defined article"
)]
return &s[prefix.len()..];
}
}
}
s
}
}