neutralts/bif/
parse_bif_count.rs1#![doc = include_str!("../../doc/bif-count.md")]
2
3use crate::{
10 constants::*,
11 bif::Bif,
12 bif::BifError,
13 bif::constants::*,
14};
15
16impl<'a> Bif<'a> {
17 pub(crate) fn parse_bif_count(&mut self) -> Result<(), BifError> {
25 if self.mod_filter || self.mod_negate || self.mod_scope {
26 return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
27 }
28
29 let is_set = self.extract_params_code(true);
30
31 if self.code.contains(BIF_OPEN) {
32 self.code = new_child_parse!(self, &self.code, self.mod_scope);
33 }
34
35 if is_set {
36 let count_name = self.params.clone();
37 let count_value = match self.code.parse::<i32>() {
38 Ok(num) => num,
39 Err(_) => {
40 return Err(self.bif_error(BIF_ERROR_ARGUMENT_NOT_NUMBER));
41 }
42 };
43
44 self.set_data(&count_name, &count_value.to_string());
45 self.out = EMPTY_STRING;
46 } else {
47 let count_name = self.code.clone();
48 let count_value = match self.get_data(&count_name).parse::<i32>() {
49 Ok(num) => num,
50 Err(_) => {
51 return Err(self.bif_error(BIF_ERROR_ARGUMENT_NOT_NUMBER));
52 }
53 };
54 let new_value = count_value + 1;
55
56 self.set_data(&count_name, &new_value.to_string());
57 self.out = count_value.to_string();
58 }
59
60 Err(self.bif_error(BIF_ERROR_BIF_DEPRECATED))
61 }
62}