neutralts/bif/
parse_bif_contains.rs1#![doc = include_str!("../../doc/bif-contains.md")]
2
3use crate::{bif::constants::*, bif::Bif, bif::BifError, constants::*};
4
5impl<'a> Bif<'a> {
6 pub(crate) fn parse_bif_contains(&mut self) -> Result<(), BifError> {
10 if self.mod_filter {
11 return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
12 }
13
14 self.extract_params_code(false);
15
16 if self.params.contains("{:flg;") {
17 return Err(self.bif_error(BIF_ERROR_FLAGS_NOT_ALLOWED));
18 }
19
20 let args = self.extract_args();
21
22 let haystack = args
23 .get(1)
24 .cloned()
25 .ok_or_else(|| self.bif_error(BIF_ERROR_ARGUMENTS_NOT_FOUND))?;
26
27 let needle = args
28 .get(2)
29 .cloned()
30 .ok_or_else(|| self.bif_error(BIF_ERROR_ARGUMENTS_NOT_FOUND))?;
31
32 if haystack.contains(&needle) ^ self.mod_negate {
33 if self.code.contains(BIF_OPEN) {
34 self.code = new_child_parse!(self, &self.code, self.mod_scope);
35 }
36 self.out = self.code.to_string();
37 } else {
38 self.out = EMPTY_STRING;
39 }
40
41 Ok(())
42 }
43}
44
45#[cfg(test)]
46#[path = "parse_bif_contains_tests.rs"]
47mod tests;