Debian Codegraph @

third_party/rust/mapped_hyph/src/main.rs

raw
1 // Copyright 2019 Mozilla Foundation. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 extern crate mapped_hyph;
11
12 use mapped_hyph::Hyphenator;
13
14 fn main() {
15 let dic_path = "hyph_en_US.hyf";
16
17 let dic = match unsafe { mapped_hyph::load_file(dic_path) } {
18 Some(dic) => dic,
19 _ => panic!("failed to load dictionary {}", dic_path),
20 };
21 let hyph = Hyphenator::new(&*dic);
22
23 println!("{}", hyph.hyphenate_word("haha", '-'));
24 println!("{}", hyph.hyphenate_word("hahaha", '-'));
25 println!("{}", hyph.hyphenate_word("photo", '-'));
26 println!("{}", hyph.hyphenate_word("photograph", '-'));
27 println!("{}", hyph.hyphenate_word("photographer", '-'));
28 println!("{}", hyph.hyphenate_word("photographic", '-'));
29 println!("{}", hyph.hyphenate_word("photographical", '-'));
30 println!("{}", hyph.hyphenate_word("photographically", '-'));
31 println!("{}", hyph.hyphenate_word("supercalifragilisticexpialidocious", '-'));
32 println!("{}", hyph.hyphenate_word("o'dwyer", '='));
33 println!("{}", hyph.hyphenate_word("o'callahan", '='));
34 println!("{}", hyph.hyphenate_word("o’dwyer", '='));
35 println!("{}", hyph.hyphenate_word("o’callahan", '='));
36 println!("{}", hyph.hyphenate_word("petti-fogging", '='));
37 println!("{}", hyph.hyphenate_word("e-mailing", '='));
38 println!("{}", hyph.hyphenate_word("-x-mailing", '='));
39 println!("{}", hyph.hyphenate_word("-strikeout-", '='));
40
41 let dic2 = match unsafe { mapped_hyph::load_file("tests/compound.hyf") } {
42 Some(dic) => dic,
43 _ => panic!("failed to load dictionary {}", "tests/compound.hyf"),
44 };
45
46 let h2 = Hyphenator::new(&*dic2);
47 println!("{}", h2.hyphenate_word("motorcycle", '='));
48
49 let dic3 = match unsafe { mapped_hyph::load_file("tests/rhmin.hyf") } {
50 Some(dic) => dic,
51 _ => panic!("failed to load dictionary {}", dic_path),
52 };
53 let h3 = Hyphenator::new(&*dic3);
54 println!("{}", h3.hyphenate_word("övéit", '='));
55 println!("{}", h3.hyphenate_word("అంగడిధర", '='));
56
57 let dic4 = match unsafe { mapped_hyph::load_file("tests/num.hyf") } {
58 Some(dic) => dic,
59 _ => panic!("failed to load dictionary {}", "tests/num.hyf"),
60 };
61 let h4 = Hyphenator::new(&*dic4);
62
63 println!("{}", h4.hyphenate_word("123foobar123", '='));
64 println!("{}", h4.hyphenate_word("123foobarfoobar", '='));
65 println!("{}", h4.hyphenate_word("foobarfoobar123", '='));
66 println!("{}", h4.hyphenate_word("123foobarfoobar123", '='));
67 }