Pārlūkot izejas kodu

added exact search for strings

nayooti 5 gadi atpakaļ
vecāks
revīzija
5bb4ee4a58

+ 16 - 0
deltachat-ios/Extensions/String+Extension.swift

@@ -13,6 +13,22 @@ extension String {
         return !trimmingCharacters(in: [" "]).isEmpty
         return !trimmingCharacters(in: [" "]).isEmpty
     }
     }
 
 
+    func containsExact(subSequence: String) -> [Int] {
+        if subSequence.count > count {
+            return []
+        }
+
+        if let range = range(of: subSequence, options: .caseInsensitive) {
+            let index: Int = distance(from: startIndex, to: range.lowerBound)
+            var indexes: [Int] = []
+            for i in index..<(index + subSequence.count) {
+                indexes.append(i)
+            }
+            return indexes
+        }
+        return []
+    }
+
     // O(n) - returns indexes of subsequences -> can be used to highlight subsequence within string
     // O(n) - returns indexes of subsequences -> can be used to highlight subsequence within string
     func contains(subSequence: String) -> [Int] {
     func contains(subSequence: String) -> [Int] {
         if subSequence.count > count {
         if subSequence.count > count {

+ 9 - 0
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -0,0 +1,9 @@
+//
+//  ChatListViewModel.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 16.03.20.
+//  Copyright © 2020 Jonas Reinsch. All rights reserved.
+//
+
+import Foundation