From 00b0af3f9db00e7755996476697e6c46de99468c Mon Sep 17 00:00:00 2001 From: lifegpc Date: Mon, 8 Sep 2025 21:10:52 +0800 Subject: [PATCH] Add scn special tokens support for fixed formatter --- src/format/fixed.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/format/fixed.rs b/src/format/fixed.rs index 1a7a68c..d81550b 100644 --- a/src/format/fixed.rs +++ b/src/format/fixed.rs @@ -71,6 +71,16 @@ impl FixedFormatter { false } + #[cfg(feature = "kirikiri")] + fn is_scn(&self) -> bool { + matches!(self.typ, Some(ScriptType::KirikiriScn)) + } + + #[cfg(not(feature = "kirikiri"))] + fn is_scn(&self) -> bool { + false + } + pub fn format(&self, message: &str) -> String { let mut result = String::new(); let vec: Vec<_> = UnicodeSegmentation::graphemes(message, true).collect(); @@ -235,6 +245,27 @@ impl FixedFormatter { } } + if self.is_scn() { + if grapheme == "%" { + is_command = true; + } else if is_command && grapheme == ";" { + is_command = false; + i += 1; + continue; + } + if grapheme == "[" { + is_ruby = true; + is_ruby_rt = true; + i += 1; + continue; + } else if is_ruby && grapheme == "]" { + is_ruby = false; + is_ruby_rt = false; + i += 1; + continue; + } + } + if is_command { if let Some(ref mut cmd) = last_command { cmd.push_str(grapheme); @@ -340,4 +371,14 @@ fn test_format() { "@re1@re2@b1@t30@w1「当然现在我很幸福哦?因为有你在身边」@n\n「@b1@t38@w1当然现在我很幸福哦?因为有敦也君在身边」" ); } + + #[cfg(feature = "kirikiri")] + { + let scn_formatter = + FixedFormatter::new(3, false, false, false, Some(ScriptType::KirikiriScn)); + assert_eq!( + scn_formatter.format("%test;[ruby]测[test]试打断。"), + "%test;[ruby]测[test]试打\n断。" + ); + } }