• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4 
5 // A sample application which takes a comma separated list of language identifiers,
6 // filters out identifiers with language subtags different than `en` and serializes
7 // the list back into a comma separated list in canonical syntax.
8 //
9 // Note: This is an example of the API use, and is not a good base for language matching.
10 // For language matching, please consider algorithms such as Locale Matcher.
11 
12 #![no_main] // https://github.com/unicode-org/icu4x/issues/395
13 icu_benchmark_macros::instrument!();
14 use icu_benchmark_macros::println;
15 
16 use std::env;
17 
18 use icu_locale_core::{subtags, LanguageIdentifier};
19 
20 const DEFAULT_INPUT: &str =
21     "de, en-us, zh-hant, sr-cyrl, fr-ca, es-cl, pl, en-latn-us, ca-valencia, und-arab";
22 
main()23 fn main() {
24     for input in env::args()
25         .nth(1)
26         .as_deref()
27         .unwrap_or(DEFAULT_INPUT)
28         .split(',')
29         .map(str::trim)
30     {
31         // 1. Parse the input string into a language identifier.
32         let Ok(langid) = LanguageIdentifier::try_from_str(input) else {
33             continue;
34         };
35         // 2. Filter for LanguageIdentifiers with Language subtag `en`.
36         if langid.language == subtags::language!("en") {
37             println!("✅ {}", langid)
38         } else {
39             println!("❌ {}", langid)
40         }
41     }
42 }
43