lawkit_core/common/input/
parser.rs1use super::file_detector::{detect_file_format, parse_file_by_format};
2use crate::common::international::extract_numbers_international;
3use std::path::Path;
4
5use crate::error::Result;
7
8pub fn parse_text_input(text: &str) -> Result<Vec<f64>> {
9 let numbers = extract_numbers_international(text);
10
11 if numbers.is_empty() {
12 return Err(crate::error::BenfError::NoNumbersFound);
13 }
14
15 Ok(numbers)
16}
17
18pub fn parse_file_input(file_path: &Path) -> Result<Vec<f64>> {
20 if !file_path.exists() {
22 return Err(crate::error::BenfError::FileError(format!(
23 "File not found: {}",
24 file_path.display()
25 )));
26 }
27
28 let format = detect_file_format(file_path);
30
31 parse_file_by_format(file_path, &format)
33}
34
35pub fn parse_input_auto(input: &str) -> Result<Vec<f64>> {
37 let path = Path::new(input);
38
39 if path.exists() {
40 parse_file_input(path)
42 } else {
43 parse_text_input(input)
45 }
46}