1// Copyright 2015 The Servo Project Developers. See the
2// COPYRIGHT file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use crate::BidiClass;
11
12/// This is the return value of [`BidiDataSource::bidi_matched_opening_bracket()`].
13///
14/// It represents the matching *normalized* opening bracket for a given bracket in a bracket pair,
15/// and whether or not that bracket is opening.
16#[derive(Debug, Copy, Clone)]
17pub struct BidiMatchedOpeningBracket {
18 /// The corresponding opening bracket in this bracket pair, normalized
19 ///
20 /// In case of opening brackets, this will be the bracket itself, except for when the bracket
21 /// is not normalized, in which case it will be the normalized form.
22 pub opening: char,
23 /// Whether or not the requested bracket was an opening bracket. True for opening
24 pub is_open: bool,
25}
26
27/// This trait abstracts over a data source that is able to produce the Unicode Bidi class for a given
28/// character
29pub trait BidiDataSource {
30 fn bidi_class(&self, c: char) -> BidiClass;
31 /// If this character is a bracket according to BidiBrackets.txt,
32 /// return the corresponding *normalized* *opening bracket* of the pair,
33 /// and whether or not it itself is an opening bracket.
34 ///
35 /// This effectively buckets brackets into equivalence classes keyed on the
36 /// normalized opening bracket.
37 ///
38 /// The default implementation will pull in a small amount of hardcoded data,
39 /// regardless of the `hardcoded-data` feature. This is in part for convenience
40 /// (since this data is small and changes less often), and in part so that this method can be
41 /// added without needing a breaking version bump.
42 /// Override this method in your custom data source to prevent the use of hardcoded data.
43 fn bidi_matched_opening_bracket(&self, c: char) -> Option<BidiMatchedOpeningBracket> {
44 crate::char_data::bidi_matched_opening_bracket(c)
45 }
46}
47