UPE // Regex Optimization.

This commit is contained in:
ShikiSuen 2022-03-05 11:13:37 +08:00
parent 30e3311ad9
commit 512ddd779c
1 changed files with 7 additions and 9 deletions

View File

@ -31,15 +31,13 @@ extension String {
var strProcessed = self var strProcessed = self
// //
strProcessed = strProcessed.replacingOccurrences(of: " #MACOS", with: "") // macOS strProcessed = strProcessed.replacingOccurrences(of: " #MACOS", with: "") // macOS
strProcessed = strProcessed.replacingOccurrences(of: " ", with: " ") // CJKWhiteSpace (\x{3000}) to ASCII Space // CJKWhiteSpace (\x{3000}) to ASCII Space
strProcessed = strProcessed.replacingOccurrences(of: " ", with: " ") // NonBreakWhiteSpace (\x{A0}) to ASCII Space // NonBreakWhiteSpace (\x{A0}) to ASCII Space
strProcessed = strProcessed.replacingOccurrences(of: "\t", with: " ") // Tab to ASCII Space // Tab to ASCII Space
strProcessed.regReplace(pattern: "\\f", replaceWith: "\n") // Form Feed to LF // ASCII
strProcessed = strProcessed.replacingOccurrences(of: "\r", with: "\n") // CR to LF strProcessed.regReplace(pattern: #"( +| +| +|\t+)+"#, replaceWith: " ")
strProcessed.regReplace(pattern: " +", replaceWith: " ") // ASCII strProcessed.regReplace(pattern: #"(\f+|\r+)+"#, replaceWith: "\n") // CR & Form Feed to LF
strProcessed.regReplace(pattern: "\\n+", replaceWith: "\n") // LF LF strProcessed.regReplace(pattern: #"(\n+| \n+|\n+ )"#, replaceWith: "\n") //
strProcessed = strProcessed.replacingOccurrences(of: " \n", with: "\n") //
strProcessed = strProcessed.replacingOccurrences(of: "\n ", with: "\n") //
if strProcessed.prefix(1) == " " { // if strProcessed.prefix(1) == " " { //
strProcessed.removeFirst() strProcessed.removeFirst()
} }