msg_tool\format/
mod.rs

1//! Module for formatting messages.
2mod fixed;
3
4use crate::types::*;
5use anyhow::Result;
6
7/// Formats messages with the given options.
8pub fn fmt_message(mes: &mut Vec<Message>, opt: FormatOptions, typ: ScriptType) -> Result<()> {
9    match opt {
10        FormatOptions::Fixed {
11            length,
12            keep_original,
13            break_words,
14            insert_fullwidth_space_at_line_start,
15            break_with_sentence,
16            #[cfg(feature = "jieba")]
17            break_chinese_words,
18            #[cfg(feature = "jieba")]
19            jieba_dict,
20            no_remove_space_at_line_start,
21        } => {
22            let formatter = fixed::FixedFormatter::new(
23                length,
24                keep_original,
25                break_words,
26                insert_fullwidth_space_at_line_start,
27                break_with_sentence,
28                #[cfg(feature = "jieba")]
29                break_chinese_words,
30                #[cfg(feature = "jieba")]
31                jieba_dict,
32                no_remove_space_at_line_start,
33                Some(typ),
34            )?;
35            for message in mes.iter_mut() {
36                message.message = formatter.format(&message.message);
37            }
38        }
39        FormatOptions::None => {}
40    }
41    Ok(())
42}