mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-14 17:04:18 +08:00
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
//! Module for formatting messages.
|
|
mod fixed;
|
|
|
|
use crate::types::*;
|
|
use anyhow::Result;
|
|
|
|
/// Formats messages with the given options.
|
|
pub fn fmt_message(mes: &mut Vec<Message>, opt: FormatOptions, typ: ScriptType) -> Result<()> {
|
|
match opt {
|
|
FormatOptions::Fixed {
|
|
length,
|
|
keep_original,
|
|
break_words,
|
|
insert_fullwidth_space_at_line_start,
|
|
break_with_sentence,
|
|
#[cfg(feature = "jieba")]
|
|
break_chinese_words,
|
|
#[cfg(feature = "jieba")]
|
|
jieba_dict,
|
|
no_remove_space_at_line_start,
|
|
} => {
|
|
let formatter = fixed::FixedFormatter::new(
|
|
length,
|
|
keep_original,
|
|
break_words,
|
|
insert_fullwidth_space_at_line_start,
|
|
break_with_sentence,
|
|
#[cfg(feature = "jieba")]
|
|
break_chinese_words,
|
|
#[cfg(feature = "jieba")]
|
|
jieba_dict,
|
|
no_remove_space_at_line_start,
|
|
Some(typ),
|
|
)?;
|
|
for message in mes.iter_mut() {
|
|
message.message = formatter.format(&message.message);
|
|
}
|
|
}
|
|
FormatOptions::None => {}
|
|
}
|
|
Ok(())
|
|
}
|