| import Foundation |
|
|
| |
| |
| |
| |
| |
| |
| enum CharClasses { |
|
|
| |
| |
| |
| private static let cjkRanges: [ClosedRange<UInt32>] = [ |
| 0x4E00...0x9FFF, |
| 0x3400...0x4DBF, |
| 0xF900...0xFAFF, |
| 0x3000...0x303F, |
| 0xFF00...0xFFEF, |
| ] |
|
|
| @inline(__always) |
| static func isCJK(_ s: Unicode.Scalar) -> Bool { |
| let cp = s.value |
| for r in cjkRanges where r.contains(cp) { return true } |
| return false |
| } |
|
|
| |
| |
| @inline(__always) |
| static func isSpace(_ s: Unicode.Scalar) -> Bool { |
| if s.properties.isWhitespace { return true } |
| switch s.value { |
| case 0x09...0x0D, 0x1C...0x1F, 0x85: return true |
| default: return false |
| } |
| } |
|
|
| |
| static let asciiPunctuation: Set<Unicode.Scalar> = { |
| let chars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" |
| return Set(chars.unicodeScalars) |
| }() |
|
|
| |
| |
| static let clausePunct: Set<Unicode.Scalar> = { |
| let chars = ",;:)]}—–" |
| + ",、;:" |
| + "”’" |
| return Set(chars.unicodeScalars) |
| }() |
|
|
| |
| static let cjkSentencePunct: Set<Unicode.Scalar> = { |
| Set("。!?…".unicodeScalars) |
| }() |
|
|
| |
| |
| static let connectors: Set<String> = [ |
| "and", "but", "or", "nor", "yet", "so", "for", |
| "which", "that", "who", "whom", "whose", "where", "when", "while", |
| "because", "although", "though", "since", "if", "unless", "until", |
| "after", "before", "as", "than", "whether", |
| ] |
| } |
|
|