Add do not break chinese word support for fixed formatter

This commit is contained in:
2025-09-15 11:40:21 +08:00
parent 1567c16273
commit 56a79106c4
9 changed files with 426 additions and 20 deletions

View File

@@ -2,9 +2,10 @@
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) {
pub fn fmt_message(mes: &mut Vec<Message>, opt: FormatOptions, typ: ScriptType) -> Result<()> {
match opt {
FormatOptions::Fixed {
length,
@@ -12,6 +13,10 @@ pub fn fmt_message(mes: &mut Vec<Message>, opt: FormatOptions, typ: ScriptType)
break_words,
insert_fullwidth_space_at_line_start,
break_with_sentence,
#[cfg(feature = "jieba")]
break_chinese_words,
#[cfg(feature = "jieba")]
jieba_dict,
} => {
let formatter = fixed::FixedFormatter::new(
length,
@@ -19,12 +24,17 @@ pub fn fmt_message(mes: &mut Vec<Message>, opt: FormatOptions, typ: ScriptType)
break_words,
insert_fullwidth_space_at_line_start,
break_with_sentence,
#[cfg(feature = "jieba")]
break_chinese_words,
#[cfg(feature = "jieba")]
jieba_dict,
Some(typ),
);
)?;
for message in mes.iter_mut() {
message.message = formatter.format(&message.message);
}
}
FormatOptions::None => {}
}
Ok(())
}