瀏覽代碼

added exact search for strings

nayooti 5 年之前
父節點
當前提交
5bb4ee4a58
共有 2 個文件被更改,包括 25 次插入0 次删除
  1. 16 0
      deltachat-ios/Extensions/String+Extension.swift
  2. 9 0
      deltachat-ios/ViewModel/ChatListViewModel.swift

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

@@ -13,6 +13,22 @@ extension String {
         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
     func contains(subSequence: String) -> [Int] {
         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