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
use ucfirst::ucfirst;

pub fn title_case<'a>(now: impl IntoIterator<Item = &'a str>, pre: &str) -> String {
  now
    .into_iter()
    .map(|i| {
      // i18n 是什么?-> What Is i18n ?

      let mut t = String::new();
      for j in i.chars() {
        if "?!.;".contains(j) {
          break;
        }
        t.push(j);
      }

      if pre.contains(&t) {
        i.into()
      } else {
        ucfirst(i)
      }
    })
    .collect::<Vec<_>>()
    .join(" ")
}