Skip to content

Commit 16603a1

Browse files
committed
fix: strip control chars
Signed-off-by: 82Flex <82flex@gmail.com>
1 parent f41cce0 commit 16603a1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

TrollFools/AppListModel.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ extension AppListModel {
223223

224224
for app in apps {
225225
var key = app.name
226+
.trimmingCharacters(in: .controlCharacters)
227+
.trimmingCharacters(in: .whitespacesAndNewlines)
226228
.applyingTransform(.stripCombiningMarks, reverse: false)?
227229
.applyingTransform(.toLatin, reverse: false)?
228230
.applyingTransform(.stripDiacritics, reverse: false)?
@@ -243,7 +245,17 @@ extension AppListModel {
243245
groupedApps[key]?.append(app)
244246
}
245247

246-
groupedApps.sort { $0.key < $1.key }
248+
groupedApps.sort { app1, app2 in
249+
if let c1 = app1.key.first,
250+
let c2 = app2.key.first,
251+
let idx1 = allowedCharacters.firstIndex(of: c1),
252+
let idx2 = allowedCharacters.firstIndex(of: c2)
253+
{
254+
return idx1 < idx2
255+
}
256+
return app1.key < app2.key
257+
}
258+
247259
return groupedApps
248260
}
249261
}

0 commit comments

Comments
 (0)