Skip to main content

builtin_pattern_set

Function builtin_pattern_set 

Source
pub fn builtin_pattern_set(name: &str) -> Option<&'static PatternSet>
Expand description

The built-in pattern set of that name, compiled on first use, or None if there is none. builtin_pattern_set_names lists and describes them.

Examples found in repository?
examples/justify.rs (line 76)
57fn main() {
58    // Break the text into lines.
59    let (mut lines, mut start, mut prev) = (Vec::new(), 0, 0);
60    for brk in LineSegmenter::new_auto(LineBreakOptions::default()).segment_str(TEXT) {
61        if TEXT[start..brk].trim_end().chars().count() > WIDTH {
62            lines.push(TEXT[start..prev].trim_end());
63            start = prev;
64        }
65        prev = brk;
66    }
67    lines.push(TEXT[start..].trim_end());
68
69    // Print the unjustified lines.
70    println!("unjustified");
71    for line in &lines {
72        println!("{line}");
73    }
74
75    // Print justified lines, the last line is unjustified.
76    let pattern_set = builtin_pattern_set("arabic-naskh").unwrap();
77    println!("\njustified");
78    let last = lines.pop().unwrap();
79    for line in lines {
80        println!("{}", justify(line, pattern_set));
81    }
82    println!("{last}");
83}