From 90ccadc5800abadb8b0722d75e8d23865699721a Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sun, 17 Jul 2022 16:52:21 +0800 Subject: [PATCH] LMs // CRLF compatibility. --- Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift | 3 ++- Source/Modules/LangModelRelated/SubLMs/lmCoreEX.swift | 3 ++- Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift b/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift index 67c2bef9..10cd3df2 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift @@ -52,7 +52,8 @@ extension vChewing { do { strData = try String(contentsOfFile: path, encoding: .utf8).replacingOccurrences(of: "\t", with: " ") - strData.ranges(splitBy: "\n").forEach { + strData = strData.replacingOccurrences(of: "\r", with: "\n") + strData.ranges(splitBy: "\n").filter({ !$0.isEmpty }).forEach { let neta = strData[$0].split(separator: " ") if neta.count >= 2 { let theKey = String(neta[0]) diff --git a/Source/Modules/LangModelRelated/SubLMs/lmCoreEX.swift b/Source/Modules/LangModelRelated/SubLMs/lmCoreEX.swift index 49978808..19eb1179 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmCoreEX.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmCoreEX.swift @@ -86,7 +86,8 @@ extension vChewing { do { strData = try String(contentsOfFile: path, encoding: .utf8).replacingOccurrences(of: "\t", with: " ") - strData.ranges(splitBy: "\n").forEach { + strData = strData.replacingOccurrences(of: "\r", with: "\n") + strData.ranges(splitBy: "\n").filter({ !$0.isEmpty }).forEach { let neta = strData[$0].split(separator: " ") if neta.count >= 2, String(neta[0]).first != "#" { if !neta[0].isEmpty, !neta[1].isEmpty { diff --git a/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift b/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift index f70cb1d7..d7df5a93 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift @@ -52,7 +52,8 @@ extension vChewing { do { strData = try String(contentsOfFile: path, encoding: .utf8).replacingOccurrences(of: "\t", with: " ") - strData.ranges(splitBy: "\n").forEach { + strData = strData.replacingOccurrences(of: "\r", with: "\n") + strData.ranges(splitBy: "\n").filter({ !$0.isEmpty }).forEach { let neta = strData[$0].split(separator: " ") if neta.count >= 2 { let theKey = String(neta[0])