neutralts/bif/
parse_bif_trans.rs

1#![doc = include_str!("../../doc/bif-trans.md")]
2
3use crate::{bif::constants::*, bif::Bif, bif::BifError, constants::*};
4
5impl<'a> Bif<'a> {
6    /*
7       {:trans; ... :}
8    */
9    pub(crate) fn parse_bif_trans(&mut self) -> Result<(), BifError> {
10        if self.mod_filter || self.mod_scope {
11            return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
12        }
13
14        // For performance, we avoid calling BlockParser::new if it is not necessary
15        if self.src.contains(BIF_OPEN) {
16            self.src = new_child_parse!(self, &self.src, self.mod_scope);
17        }
18
19        let trans = self.get_trans(&self.src);
20
21        // By default the input text
22        if trans.is_empty() {
23            if self.mod_negate {
24                self.out = EMPTY_STRING;
25            } else {
26                self.out = self.src.clone();
27            }
28        } else {
29            self.out = trans;
30        }
31
32        Ok(())
33    }
34}
35
36#[cfg(test)]
37#[path = "parse_bif_trans_tests.rs"]
38mod tests;