diff --git a/Info.plist b/Info.plist
index d6fdb03..e4836b0 100644
--- a/Info.plist
+++ b/Info.plist
@@ -19,7 +19,7 @@
CFBundlePackageType
APPL
CFBundleShortVersionString
- 2.13
+ 2.14
CFBundleVersion
1
LSMinimumSystemVersion
diff --git a/src/TextProcessor.swift b/src/TextProcessor.swift
index 05d50ad..c1882b9 100644
--- a/src/TextProcessor.swift
+++ b/src/TextProcessor.swift
@@ -74,22 +74,26 @@ public final class TextProcessor {
/// Lightweight inline formatter applied to live streaming chunks so words, domain terms,
/// and numbers match the final post-processed text in real time.
public func processLiveChunk(_ text: String) -> String {
- if text.isEmpty { return "" }
- let hasLeadingSpace = text.first?.isWhitespace == true
- let hasTrailingSpace = text.last?.isWhitespace == true
+ if text.isEmpty { return "" }
+ let hadLeadingSpace = text.first?.isWhitespace == true
+ let hadTrailingSpace = text.last?.isWhitespace == true
- var result = text
- if SonioxSettings.shared.voicePunctuation {
- result = applyVoicePunctuation(result)
- }
- if SonioxSettings.shared.domainVocabulary {
- result = applyDomainVocabulary(result)
- }
- result = applyNumberFormatting(result, format: SonioxSettings.shared.numberFormat)
+ var result = text
+ if SonioxSettings.shared.voicePunctuation {
+ result = applyVoicePunctuation(result)
+ }
+ if SonioxSettings.shared.domainVocabulary {
+ result = applyDomainVocabulary(result)
+ }
+ result = applyNumberFormatting(result, format: SonioxSettings.shared.numberFormat)
- let trimmed = result.trimmingCharacters(in: .whitespaces)
- if trimmed.isEmpty { return text }
- return (hasLeadingSpace ? " " : "") + trimmed + (hasTrailingSpace ? " " : "")
+ let resultHasLeadingSpace = result.first?.isWhitespace == true
+ let resultHasTrailingSpace = result.last?.isWhitespace == true
+ let trimmed = result.trimmingCharacters(in: .whitespaces)
+ if trimmed.isEmpty { return text }
+ let keepLeading = hadLeadingSpace || resultHasLeadingSpace
+ let keepTrailing = hadTrailingSpace || resultHasTrailingSpace
+ return (keepLeading ? " " : "") + trimmed + (keepTrailing ? " " : "")
}
public func applyDomainVocabularyInline(_ text: String) -> String {