bvreader/bv_reader/header/parser/
parse_sinterval.rs

1use regex::Regex;
2use std::sync::OnceLock;
3
4use crate::bv_reader::generic_parser::parse_generic_value;
5
6static SINTER_REGEX: OnceLock<Regex> = OnceLock::new();
7/// Returns the sampling interval or Option::None
8pub fn parse_sampling_interval(textcontent: &str) -> Option<usize> {
9    let re = SINTER_REGEX.get_or_init(|| {
10        Regex::new(r"SamplingInterval=(\d*)").unwrap() 
11      }); 
12    parse_generic_value::<usize>(textcontent, re)
13}
14
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19
20    #[test]
21    fn test_parse_sampling_interval() {
22        let input = "[Common Infos]
23        Codepage=UTF-8
24        DataFile=01_data.eeg
25        MarkerFile=01_marker.vmrk
26        DataFormat=BINARY
27        ; Data orientation: MULTIPLEXED=ch1,pt1, ch2,pt1 ...
28        DataOrientation=MULTIPLEXED
29        NumberOfChannels=71
30        ; Sampling interval in microseconds
31        SamplingInterval=2000";
32        let output = parse_sampling_interval(input).unwrap();
33        let expected = 2000;
34        assert_eq!(output, expected);
35    }
36
37    #[test]
38    fn test_parse_sampling_interval_empty() {
39        let input = "[Common Infos]
40        Codepage=
41        DataFil";
42        let output = parse_sampling_interval(input);
43        let expected = Option::None;
44        assert_eq!(output, expected);
45    }
46
47}