Skip to content

Commit e1b76b6

Browse files
committed
Implement Collection.isNotEmpty
1 parent fff85c4 commit e1b76b6

19 files changed

+75
-37
lines changed

CoreIME/Sources/CoreIME/Candidate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public struct Candidate: Hashable {
129129

130130
/// Concatenated by multiple lexicons
131131
public var isCompound: Bool {
132-
return !(subNotations.isEmpty)
132+
return subNotations.isNotEmpty
133133
}
134134

135135
// Equatable

CoreIME/Sources/CoreIME/Emoji.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension Engine {
5050
let regular: [Candidate] = match(text: text, input: text)
5151
let textCount = text.count
5252
let schemes = segmentation.filter({ $0.length == textCount })
53-
guard !(schemes.isEmpty) else { return regular }
53+
guard schemes.isNotEmpty else { return regular }
5454
let matches = schemes.map({ scheme -> [Candidate] in
5555
let pingText = scheme.map(\.origin).joined()
5656
return match(text: pingText, input: text)

CoreIME/Sources/CoreIME/Engine.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public struct Engine {
248248
guard canProcess(tailText) else { return [] }
249249
let tailSegmentation = Segmentor.segment(text: tailText)
250250
let tailCandidates = process(text: tailText, segmentation: tailSegmentation, needsSymbols: needsSymbols, limit: 8).prefix(100)
251-
guard !(tailCandidates.isEmpty) else { return [] }
251+
guard tailCandidates.isNotEmpty else { return [] }
252252
let headCandidates = primary.filter({ $0.input == headText }).prefix(8)
253253
let combines = headCandidates.map({ head -> [Candidate] in
254254
return tailCandidates.map({ head + $0 })
@@ -266,11 +266,11 @@ public struct Engine {
266266
let matched = match(text: text, input: text, limit: limit)
267267
let regularCandidates: [Candidate] = {
268268
var items = matched + preferredSearches
269-
guard !(items.isEmpty) else { return items }
269+
guard items.isNotEmpty else { return items }
270270
guard limit == nil else { return items }
271271
guard needsSymbols else { return items }
272272
let symbols: [Candidate] = Engine.searchSymbols(text: text, segmentation: segmentation)
273-
guard !(symbols.isEmpty) else { return items }
273+
guard symbols.isNotEmpty else { return items }
274274
for symbol in symbols.reversed() {
275275
if let index = items.firstIndex(where: { $0.lexiconText == symbol.lexiconText }) {
276276
items.insert(symbol, at: index + 1)
@@ -284,7 +284,7 @@ public struct Engine {
284284
private static func search(text: String, segmentation: Segmentation, limit: Int? = nil) -> [Candidate] {
285285
let textCount: Int = text.count
286286
let perfectSchemes = segmentation.filter({ $0.length == textCount })
287-
if !(perfectSchemes.isEmpty) {
287+
if perfectSchemes.isNotEmpty {
288288
let matches = perfectSchemes.map({ scheme -> [Candidate] in
289289
var queries: [[Candidate]] = []
290290
for number in (0..<scheme.count) {

CoreIME/Sources/CoreIME/Extensions/CollectionExtensions.swift

+6
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ extension Collection where Element: Collection {
55
return self.map(\.count).reduce(0, +)
66
}
77
}
8+
9+
extension Collection {
10+
var isNotEmpty: Bool {
11+
return !(self.isEmpty)
12+
}
13+
}

CoreIME/Sources/CoreIME/Pinyin.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension Engine {
4343
let tailText = String(text.dropFirst(headInputCount))
4444
let tailSegmentation = PinyinSegmentor.segment(text: tailText)
4545
let tailCandidates = process(pinyin: tailText, schemes: tailSegmentation, limit: 8).prefix(100)
46-
guard !(tailCandidates.isEmpty) else { return [] }
46+
guard tailCandidates.isNotEmpty else { return [] }
4747
let headCandidates = primary.filter({ $0.input == headText }).prefix(8)
4848
let combines = headCandidates.map({ head -> [PinyinLexicon] in
4949
return tailCandidates.map({ head + $0 })
@@ -65,7 +65,7 @@ extension Engine {
6565
private static func search(pinyin text: String, schemes: [[String]], limit: Int? = nil) -> [PinyinLexicon] {
6666
let textCount: Int = text.count
6767
let perfectSchemes = schemes.filter({ $0.summedLength == textCount })
68-
if !(perfectSchemes.isEmpty) {
68+
if perfectSchemes.isNotEmpty {
6969
let matches = perfectSchemes.map({ scheme -> [PinyinLexicon] in
7070
var queries: [[PinyinLexicon]] = []
7171
for number in (0..<scheme.count) {

CoreIME/Sources/CoreIME/PinyinSegmentor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct PinyinSegmentor {
2121

2222
private static func split(_ text: String) -> [[String]] {
2323
let leadingTokens: [String] = splitLeading(text)
24-
guard !(leadingTokens.isEmpty) else { return [] }
24+
guard leadingTokens.isNotEmpty else { return [] }
2525
let textCount = text.count
2626
var segmentation: [[String]] = leadingTokens.map({ [$0] })
2727
var previousSubelementCount = segmentation.subelementCount
@@ -32,7 +32,7 @@ public struct PinyinSegmentor {
3232
guard schemeLength < textCount else { continue }
3333
let tailText = String(text.dropFirst(schemeLength))
3434
let tailTokens = splitLeading(tailText)
35-
guard !(tailTokens.isEmpty) else { continue }
35+
guard tailTokens.isNotEmpty else { continue }
3636
let newSegmentation: [[String]] = tailTokens.map({ scheme + [$0] })
3737
segmentation += newSegmentation
3838
}

CoreIME/Sources/CoreIME/Segmentor.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public struct Segmentor {
9595

9696
private static func split(text: String) -> Segmentation {
9797
let leadingTokens = splitLeading(text)
98-
guard !(leadingTokens.isEmpty) else { return [] }
98+
guard leadingTokens.isNotEmpty else { return [] }
9999
let textCount = text.count
100100
var segmentation: Segmentation = leadingTokens.map({ [$0] })
101101
var previousSubelementCount = segmentation.subelementCount
@@ -106,7 +106,7 @@ public struct Segmentor {
106106
guard schemeLength < textCount else { continue }
107107
let tailText = text.dropFirst(schemeLength)
108108
let tailTokens = splitLeading(tailText)
109-
guard !(tailTokens.isEmpty) else { continue }
109+
guard tailTokens.isNotEmpty else { continue }
110110
let newSegmentation: Segmentation = tailTokens.map({ scheme + [$0] })
111111
segmentation += newSegmentation
112112
}
@@ -136,6 +136,8 @@ public struct Segmentor {
136136
default:
137137
return []
138138
}
139+
case 4 where text == "mama":
140+
return mama
139141
default:
140142
let rawText: String = text.filter({ !$0.isSeparatorOrTone })
141143
let key: Int = rawText.hash
@@ -160,4 +162,5 @@ public struct Segmentor {
160162
private static let letterA: Segmentation = [[SegmentToken(text: "a", origin: "aa")]]
161163
private static let letterO: Segmentation = [[SegmentToken(text: "o", origin: "o")]]
162164
private static let letterM: Segmentation = [[SegmentToken(text: "m", origin: "m")]]
165+
private static let mama: Segmentation = [[SegmentToken(text: "ma", origin: "maa"), SegmentToken(text: "ma", origin: "maa")]]
163166
}

CoreIME/Sources/CoreIME/Simplifier.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ struct Simplifier {
3636

3737
private static func transform(_ text: String) -> String {
3838
let roundOne = replace(text, replacement: "W")
39-
guard !(roundOne.matched.isEmpty) else {
39+
guard roundOne.matched.isNotEmpty else {
4040
return text.map(Engine.matchT2S(_:)).joined()
4141
}
4242

4343
let roundTwo = replace(roundOne.modified, replacement: "X")
44-
guard !(roundTwo.matched.isEmpty) else {
44+
guard roundTwo.matched.isNotEmpty else {
4545
let transformed: String = roundTwo.modified.map(Engine.matchT2S(_:)).joined()
4646
let reverted: String = transformed.replacingOccurrences(of: roundOne.replacement, with: roundOne.matched)
4747
return reverted
4848
}
4949

5050
let roundThree = replace(roundTwo.modified, replacement: "Y")
51-
guard !(roundThree.matched.isEmpty) else {
51+
guard roundThree.matched.isNotEmpty else {
5252
let transformed: String = roundThree.modified.map(Engine.matchT2S(_:)).joined()
5353
let reverted: String = transformed
5454
.replacingOccurrences(of: roundOne.replacement, with: roundOne.matched)
@@ -57,7 +57,7 @@ struct Simplifier {
5757
}
5858

5959
let roundFour = replace(roundThree.modified, replacement: "Z")
60-
guard !(roundFour.matched.isEmpty) else {
60+
guard roundFour.matched.isNotEmpty else {
6161
let transformed: String = roundFour.modified.map(Engine.matchT2S(_:)).joined()
6262
let reverted: String = transformed
6363
.replacingOccurrences(of: roundOne.replacement, with: roundOne.matched)

Preparing/Sources/Preparing/Resources/symbol.txt

+23-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
1 1F618 飛吻 fei1 man5 792105 9200832787368950
5252
1 1F618 示愛 si6 oi3 808820 37893924664
5353
1 1F617 開眼𡃶 hoi1 ngaan5 sek3 520391340 -7078768452912759149
54-
1 1F61A 瞇眼𡃶 mai4 ngaan5 sek3 523363545 3381707220720626314
54+
1 1F61A 眯眼𡃶 mei1 ngaan5 sek3 523363545 -1781229424199504242
5555
1 1F619 𡃶啖 sek3 daam6 808765 5323868975028160605
5656
1 1F619 𡃶𡃶 sek3 sek3 808840 10148210904524940
5757
1 1F60B 伸脷 san1 lei6 808805 10147079942213890
@@ -244,8 +244,8 @@
244244
1 1FAE4 冇嘢好講 mou5 je5 hou2 gong2 36163608394 6965070078788889123
245245
1 1FAE4 無話可說 mou4 waa6 ho2 syut3 36178205427 -9056198250981294014
246246
1 1F611 冇眼睇 mou5 ngaan5 tai2 523363554 -5130692063828398433
247-
1 1F611 瞇埋眼 mei1 maai4 ngaan5 523361187 832951943302584548
248-
1 1F611 瞇眼 mei1 ngaan5 801105 4689576242071273800
247+
1 1F611 眯埋眼 mei1 maai4 ngaan5 523361187 832951943302584548
248+
1 1F611 眯眼 mei1 ngaan5 801105 4689576242071273800
249249
1 1FAE8 頭震 tau4 zan3 810160 10219962793740505
250250
1 1FAE8 面震 min6 zan3 801165 9712098078568275
251251
1 1FAE8 模糊 mou4 wu4 801150 18616709162370
@@ -419,6 +419,7 @@
419419
1 270C.FE0F 好嘢 hou2 je5 794660 17896901435424
420420
1 270C.FE0F 手勢二 sau2 sai3 ji6 526941675 6451928239219442529
421421
1 270C.FE0F 二 ji6 1089 797225
422+
1 270C.FE0F 㖿 je1 1089 797205
422423
1 1FAF0 錢銀 cin2 ngan2 788255 4729734830465070693
423424
1 1FAF0 錢 cin4 1068 517407525
424425
1 1FAF0 錢 cin2 1068 517407525
@@ -507,6 +508,7 @@
507508
1 1F9B5 下肢 haa6 zi1 794740 17889015716946
508509
1 1F9BF 機械腳 gei1 haai6 goek3 519782913 -2899980437418590343
509510
1 1F9BF 義肢 ji6 zi1 797310 35296859994
511+
1 1F9BF 假肢 gaa2 zi1 793455 17745054193713
510512
1 1F484 口紅 hau2 hung4 794650 4914429965755181175
511513
1 1F48B 紅脣 hung4 seon4 794705 3235530381661871215
512514
1 1F48B 脣 seon4 1116 37889433417
@@ -1093,6 +1095,8 @@
10931095
1 1F458 和服 wo4 fuk6 813915 20056291683153
10941096
1 1F97B 紗麗 saa1 lai6 808805 10147065598615985
10951097
1 1FA74 人字拖 jan4 zi6 to1 521607987 4988765362096407558
1098+
1 1FA74 鞋拖 haai2 to1 794710 9345439837518460
1099+
1 1FA74 膠拖 gaau1 to1 793425 9272564820987975
10961100
1 1FA74 拖鞋 to1 haai2 810070 10223918190944380
10971101
1 1FA74 涼鞋 loeng4 haai4 799790 2063708859358878385
10981102
1 1F97F 平底鞋 ping4 dai2 haai4 525123639 -4827144367670830214
@@ -1262,7 +1266,15 @@
12621266
2 1F41D 蜜蜂 mat6 fung1 801065 5100277639464648057
12631267
2 1F41D 蜂 fung1 1077 34156009204
12641268
2 1FAB1 蠕蟲 jyu4 cung4 797195 4992240346694510604
1269+
2 1FAB1 蟲 cung4 1068 33290304961
1270+
2 1FAB1 寄生蟲 gei3 sang1 cung4 519808320 4509158353911789206
1271+
2 1FAB1 黃䘆 wong4 hyun2 813925 7645859770684343943
1272+
2 1FAB1 紅䘆 hung4 hyun2 794650 3235530334014584958
1273+
2 1FAB1 蚯蚓 jau1 jan5 797230 9491212044562495
1274+
2 1FAB1 地龍 dei6 lung4 789530 4766323144656632943
12651275
2 1F41B 蟲 cung4 1068 33290304961
1276+
2 1F41B 毛毛蟲 mou4 mou4 cung4 523361088 4129046369746115161
1277+
2 1F41B 毛蟲 mou4 cung4 801050 5102303001391023237
12661278
2 1F41B 一條蟲 jat1 tiu4 cung4 521593956 5197877627395805256
12671279
2 1F98B 蝴蝶 wu4 dip6 813905 20059648191726
12681280
2 1F98B 蝴蝶 wu4 dip2 813905 20059648191726
@@ -1281,6 +1293,9 @@
12811293
2 1F99F 蚊 man1 1098 523333431
12821294
2 1F99F 蚊 man4 1098 523333431
12831295
2 1F99F 蚊蟲 man1 cung4 801050 5100274256343390192
1296+
2 1F99F 蚊蟲 man4 cung4 801050 5100274256343390192
1297+
2 1F99F 蚊子 man1 zi2 801165 18608851668132
1298+
2 1F99F 蚊子 man4 zi2 801165 18608851668132
12841299
2 1F997 蟋蟀 sik1 seot1 808840 5324447523833361801
12851300
2 1F577.FE0F 蠄蟧 kam4 lou4 798525 9564078294643535
12861301
2 1F577.FE0F 蠄蟧 kam4 lou2 798525 9564078294643535
@@ -2195,11 +2210,14 @@
21952210
5 1F6DE 輪胎 leon4 toi1 799850 5063683710935831169
21962211
5 1F6DE 車胎 ce1 toi1 788285 17171490066489
21972212
5 1F6DE 備胎 bei6 toi1 787000 8909332545459970
2213+
5 1F6DE 車呔 ce1 taai1 788285 8982219668538285
2214+
5 1F6DE 呔 taai1 1119 38173448915
21982215
5 1F6A8 警車燈 ging2 ce1 dang1 519771321 5662412490202641
21992216
5 1F6A8 警燈 ging2 dang1 793345 2927299965815418695
22002217
5 1F6A8 警示燈 ging2 si6 dang1 519808329 24067238864981541
22012218
5 1F694 警車 ging2 ce1 793340 9274847588738355
22022219
5 1F68D 公交車 gung1 gaau1 ce1 519780564 6556062482074998305
2220+
5 1F68D 巴士 baa1 si2 786995 17025246518181
22032221
5 1F698 車 ce1 1068 788210
22042222
5 1F698 汽車 hei3 ce1 794625 17891273604963
22052223
5 1F698 轎車 giu2 ce1 793340 17749578883410
@@ -2271,6 +2289,7 @@
22712289
5 1F6A5 交通號標 gaau1 tung1 hou6 biu1 34443428153 3509265666983085558
22722290
5 1F6A5 交通燈 gaau1 tung1 dang1 519810642 8751747830600959234
22732291
5 1F68F 公交車站 gung1 gaau1 ce1 zaam6 34428809887 2975951356207030478
2292+
5 1F68F 巴士站 baa1 si2 zaam6 516836322 -4225709806478087758
22742293
5 1F5FA 地圖 dei6 tou4 789570 9055082681558160
22752294
5 1F5FF 復活節島 fuk6 wut6 zit3 dou2 34158307247 -4231958217449236399
22762295
5 1F5FF 巨石像 geoi6 sek6 zoeng6 519808527 -2898969049832257002
@@ -3737,6 +3756,7 @@
37373756
9 43.2081.2082.48.2081.2085.4E 甲基安非他命 gaap3 gei1 on1 fei1 taa1 ming6 9274281566926090 -2663076024123669293
37383757
9 43.2081.2082.48.2081.2085.4E 冰毒 bing1 duk6 786920 4692565166942596203
37393758
9 48.2082.53.4F.2084 硫酸 lau4 syun1 799845 5063108582554517784
3759+
9 43.2081.2082.48.2082.2082.4F.2081.2084.5A.6E 葡萄糖酸鋅 pou4 tou4 tong4 syun1 san1 19051392326307 -1205200220355997050
37403760
9 4EBB 企人邊 kei5 jan4 bin1 522165258 -7299778867723347276
37413761
9 4EBB 企人旁 kei5 jan4 pong4 522165384 5468037021001426736
37423762
9 4EBB 單企人 daan1 kei5 jan4 518006556 8716432916495763984

TypeDuck.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
373133122BBF302C0012A939 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 373133112BBF302C0012A939 /* PrivacyInfo.xcprivacy */; };
5757
3764F6122BFAC36400B3737B /* InfoPlist.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 3764F6112BFAC36400B3737B /* InfoPlist.xcstrings */; };
5858
3764F6142BFAC36400B3737B /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 3764F6132BFAC36400B3737B /* Localizable.xcstrings */; };
59+
378CE02A2C200DA300BA7FBA /* CollectionExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 378CE0292C200DA300BA7FBA /* CollectionExtensions.swift */; };
5960
3797F6E72C18900500DE6D0E /* PrincipalApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3797F6E62C18900500DE6D0E /* PrincipalApplication.swift */; };
6061
3797F6E92C18902900DE6D0E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3797F6E82C18902900DE6D0E /* AppDelegate.swift */; };
6162
37A619B12BAE2F5A00A0C7F9 /* typeduck@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 37A619AF2BAE2F5900A0C7F9 /* typeduck@2x.png */; };
@@ -134,6 +135,7 @@
134135
373133112BBF302C0012A939 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
135136
3764F6112BFAC36400B3737B /* InfoPlist.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = InfoPlist.xcstrings; sourceTree = "<group>"; };
136137
3764F6132BFAC36400B3737B /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
138+
378CE0292C200DA300BA7FBA /* CollectionExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionExtensions.swift; sourceTree = "<group>"; };
137139
3797F6E62C18900500DE6D0E /* PrincipalApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrincipalApplication.swift; sourceTree = "<group>"; };
138140
3797F6E82C18902900DE6D0E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
139141
37A619AF2BAE2F5900A0C7F9 /* typeduck@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "typeduck@2x.png"; sourceTree = "<group>"; };
@@ -294,6 +296,7 @@
294296
isa = PBXGroup;
295297
children = (
296298
371B27C42B3EB93A00EC1271 /* CharacterExtensions.swift */,
299+
378CE0292C200DA300BA7FBA /* CollectionExtensions.swift */,
297300
370F5B302BB59B2200F0A65C /* ColorExtensions.swift */,
298301
370F5B322BB59B4200F0A65C /* ViewExtensions.swift */,
299302
371B27C52B3EB93A00EC1271 /* FontExtensions.swift */,
@@ -468,6 +471,7 @@
468471
buildActionMask = 2147483647;
469472
files = (
470473
371B27CC2B3EB93A00EC1271 /* DisplayCandidate.swift in Sources */,
474+
378CE02A2C200DA300BA7FBA /* CollectionExtensions.swift in Sources */,
471475
371B27E12B3EB93A00EC1271 /* TypeDuckInputController.swift in Sources */,
472476
371B27E42B3EB93A00EC1271 /* Options.swift in Sources */,
473477
371B27CF2B3EB93A00EC1271 /* AppContext.swift in Sources */,

TypeDuck/AppContext.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class AppContext: ObservableObject {
2525
}
2626

2727
func update(with newDisplayCandidates: [DisplayCandidate], highlight: Highlight) {
28-
guard !(newDisplayCandidates.isEmpty) else {
28+
guard newDisplayCandidates.isNotEmpty else {
2929
resetDisplayContext()
3030
return
3131
}

TypeDuck/Candidate/DisplayCandidate.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ struct DisplayCandidate: Hashable {
1919
case .emoji, .symbol, .emojiSequence, .symbolSequence:
2020
var comments: [Comment] = []
2121
let cantoneseText = candidate.lexiconText
22-
if !(cantoneseText.isEmpty) {
22+
if cantoneseText.isNotEmpty {
2323
let cantoneseComment = Comment(language: .Cantonese, text: "\(cantoneseText)")
2424
comments.append(cantoneseComment)
2525
}
2626
return comments
2727
case .compose:
2828
var comments: [Comment] = []
2929
let cantoneseText = candidate.lexiconText
30-
if !(cantoneseText.isEmpty) {
30+
if cantoneseText.isNotEmpty {
3131
let cantoneseComment = Comment(language: .Cantonese, text: "\(cantoneseText)")
3232
comments.append(cantoneseComment)
3333
}
3434
let unicodeCodePoint = candidate.romanization
35-
if !(unicodeCodePoint.isEmpty) {
35+
if unicodeCodePoint.isNotEmpty {
3636
let unicodeComment = Comment(language: .Unicode, text: unicodeCodePoint)
3737
comments.append(unicodeComment)
3838
}

0 commit comments

Comments
 (0)