mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-15 09:34:16 +08:00
Add do not break chinese word support for fixed formatter
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user