Skip to main content

rxing/oned/rss/expanded/
expanded_pair.rs

1/*
2 * Copyright (C) 2010 ZXing authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * These authors would like to acknowledge the Spanish Ministry of Industry,
19 * Tourism and Trade, for the support in the project TSI020301-2008-2
20 * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 * Mobile Dynamic Environments", led by Treelogic
22 * ( http://www.treelogic.com/ ):
23 *
24 *   http://www.piramidepse.com/
25 */
26
27use std::fmt::Display;
28
29use crate::oned::rss::{DataCharacter, FinderPattern};
30
31/**
32 * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
33 */
34#[derive(PartialEq, Eq, Hash, Clone)]
35pub struct ExpandedPair {
36    leftChar: Option<DataCharacter>,
37    rightChar: Option<DataCharacter>,
38    finderPattern: Option<FinderPattern>,
39}
40
41impl ExpandedPair {
42    pub const fn new(
43        leftChar: Option<DataCharacter>,
44        rightChar: Option<DataCharacter>,
45        finderPattern: Option<FinderPattern>,
46    ) -> Self {
47        Self {
48            leftChar,
49            rightChar,
50            finderPattern,
51        }
52    }
53
54    pub fn getLeftChar(&self) -> &Option<DataCharacter> {
55        &self.leftChar
56    }
57
58    pub fn getRightChar(&self) -> &Option<DataCharacter> {
59        &self.rightChar
60    }
61
62    pub fn getFinderPattern(&self) -> &Option<FinderPattern> {
63        &self.finderPattern
64    }
65
66    #[cfg(all(test, feature = "image"))]
67    pub(crate) fn getFinderPatternMut(&mut self) -> &mut Option<FinderPattern> {
68        &mut self.finderPattern
69    }
70
71    pub fn mustBeLast(&self) -> bool {
72        self.rightChar.is_none()
73    }
74}
75
76impl Display for ExpandedPair {
77    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78        write!(
79            f,
80            "[ {:?} , {:?} : {} ]",
81            self.leftChar,
82            self.rightChar,
83            if let Some(fp) = &self.finderPattern {
84                fp.getValue().to_string()
85            } else {
86                "null".to_owned()
87            }
88        )
89    }
90}