fuga_remo_api/
parser_options.rs1use core::str::FromStr;
7
8use heapless::String;
9use crate::common_types::ModelNodeParseError;
10
11pub struct ParserOptions {
12 truncate_too_long_string: bool,
14}
15
16impl Default for ParserOptions {
17 fn default() -> Self {
18 Self {
19 truncate_too_long_string: true,
20 }
21 }
22}
23
24pub fn copy_string_possible<const N: usize>(s: &str) -> String<N> {
26 let mut string = String::new();
27 for c in s.chars() {
28 if let Err(_) = string.push(c) {
29 break;
30 }
31 }
32 string
33}
34
35pub fn copy_string_option<const N: usize>(s: &str, options: &ParserOptions) -> Result<String<N>, ModelNodeParseError> {
37 if options.truncate_too_long_string {
38 Ok(copy_string_possible(s))
39 } else {
40 String::from_str(s).map_err(|_| ModelNodeParseError::StringTooLong)
41 }
42}