Fix searching with special characters

This commit is contained in:
Christoph Hagen 2023-07-28 13:20:33 +02:00
parent 5394c13218
commit 68ddbf1eb3
4 changed files with 15 additions and 12 deletions

View File

@ -48,6 +48,7 @@
E2EA00ED2841170100F7B269 /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00EC2841170100F7B269 /* UIImage+Extensions.swift */; }; E2EA00ED2841170100F7B269 /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00EC2841170100F7B269 /* UIImage+Extensions.swift */; };
E2EA00EF28420AA000F7B269 /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */; }; E2EA00EF28420AA000F7B269 /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */; };
E2EA00F328438E6B00F7B269 /* CapNameEntryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00F228438E6B00F7B269 /* CapNameEntryView.swift */; }; E2EA00F328438E6B00F7B269 /* CapNameEntryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00F228438E6B00F7B269 /* CapNameEntryView.swift */; };
E2ED709A2A73D86F00067808 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2ED70992A73D86F00067808 /* String+Extensions.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
@ -92,6 +93,7 @@
E2EA00EC2841170100F7B269 /* UIImage+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Extensions.swift"; sourceTree = "<group>"; }; E2EA00EC2841170100F7B269 /* UIImage+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Extensions.swift"; sourceTree = "<group>"; };
E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = "<group>"; }; E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = "<group>"; };
E2EA00F228438E6B00F7B269 /* CapNameEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapNameEntryView.swift; sourceTree = "<group>"; }; E2EA00F228438E6B00F7B269 /* CapNameEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapNameEntryView.swift; sourceTree = "<group>"; };
E2ED70992A73D86F00067808 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -173,6 +175,7 @@
E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */, E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */,
E20D105128589AAC0019BD91 /* FileManager+Extensions.swift */, E20D105128589AAC0019BD91 /* FileManager+Extensions.swift */,
E20D10552858CDFA0019BD91 /* View+Extensions.swift */, E20D10552858CDFA0019BD91 /* View+Extensions.swift */,
E2ED70992A73D86F00067808 /* String+Extensions.swift */,
); );
path = Extensions; path = Extensions;
sourceTree = "<group>"; sourceTree = "<group>";
@ -320,6 +323,7 @@
E25AAC92283D8808006E9E7F /* CapData.swift in Sources */, E25AAC92283D8808006E9E7F /* CapData.swift in Sources */,
E25AAC96283E14DF006E9E7F /* Database.swift in Sources */, E25AAC96283E14DF006E9E7F /* Database.swift in Sources */,
E25AAC8D283D86CF006E9E7F /* Logger.swift in Sources */, E25AAC8D283D86CF006E9E7F /* Logger.swift in Sources */,
E2ED709A2A73D86F00067808 /* String+Extensions.swift in Sources */,
E20D105028574E190019BD91 /* CapImage.swift in Sources */, E20D105028574E190019BD91 /* CapImage.swift in Sources */,
E2EA00ED2841170100F7B269 /* UIImage+Extensions.swift in Sources */, E2EA00ED2841170100F7B269 /* UIImage+Extensions.swift in Sources */,
E20D105228589AAC0019BD91 /* FileManager+Extensions.swift in Sources */, E20D105228589AAC0019BD91 /* FileManager+Extensions.swift in Sources */,

View File

@ -65,9 +65,7 @@ struct ContentView: View {
private var selectedCapToShowImages: Cap? private var selectedCapToShowImages: Cap?
var filteredCaps: [Cap] { var filteredCaps: [Cap] {
let text = searchString let text = searchString.clean
.trimmingCharacters(in: .whitespacesAndNewlines)
.lowercased()
guard text != "" else { guard text != "" else {
return Array(database.caps.values) return Array(database.caps.values)
} }

View File

@ -143,15 +143,6 @@ extension Cap: Hashable {
} }
} }
// MARK: String extension
private extension String {
var clean: String {
return lowercased().replacingOccurrences(of: "[^a-z0-9 ]", with: "", options: .regularExpression)
}
}
// MARK: Int extension // MARK: Int extension
private extension Int { private extension Int {

View File

@ -0,0 +1,10 @@
import Foundation
extension String {
var clean: String {
lowercased()
.replacingOccurrences(of: "[^a-z0-9 ]", with: "", options: .regularExpression)
.trimmingCharacters(in: .whitespacesAndNewlines)
}
}