소스 검색

subsequence optional for easier use

nayooti 5 년 전
부모
커밋
57f1bbdd93
1개의 변경된 파일7개의 추가작업 그리고 4개의 파일을 삭제
  1. 7 4
      deltachat-ios/Extensions/String+Extension.swift

+ 7 - 4
deltachat-ios/Extensions/String+Extension.swift

@@ -13,15 +13,18 @@ extension String {
         return !trimmingCharacters(in: [" "]).isEmpty
     }
 
-    func containsExact(subSequence: String) -> [Int] {
-        if subSequence.count > count {
+    func containsExact(subSequence: String?) -> [Int] {
+        guard let searchText = subSequence else {
+            return []
+        }
+        if searchText.count > count {
             return []
         }
 
-        if let range = range(of: subSequence, options: .caseInsensitive) {
+        if let range = range(of: searchText, options: .caseInsensitive) {
             let index: Int = distance(from: startIndex, to: range.lowerBound)
             var indexes: [Int] = []
-            for i in index..<(index + subSequence.count) {
+            for i in index..<(index + searchText.count) {
                 indexes.append(i)
             }
             return indexes