UPE // Regex Optimization.
This commit is contained in:
parent
30e3311ad9
commit
512ddd779c
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue