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