Skip to content
This repository was archived by the owner on May 8, 2022. It is now read-only.

Commit fb62ebf

Browse files
ludodedkrisk
authored andcommitted
Fixed the error in newer Xcode 10 (#10)
* #9 Update with new initializer for Range<Index> * #9 Remove warnings corresponding to Swift 3 characters property access
1 parent 135f208 commit fb62ebf

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

Fuse/Classes/Fuse.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class Fuse {
7474
/// - Returns: A tuple containing pattern metadata
7575
public func createPattern (from aString: String) -> Pattern? {
7676
let pattern = self.isCaseSensitive ? aString : aString.lowercased()
77-
let len = pattern.characters.count
77+
let len = pattern.count
7878

7979
if len == 0 {
8080
return nil
@@ -109,7 +109,7 @@ public class Fuse {
109109
text = text.lowercased()
110110
}
111111

112-
let textLength = text.characters.count
112+
let textLength = text.count
113113

114114
// Exact match
115115
if (pattern.text == text) {
@@ -122,7 +122,7 @@ public class Fuse {
122122

123123
var bestLocation: Int? = {
124124
if let index = text.index(of: pattern.text, startingFrom: location) {
125-
return text.characters.distance(from: text.startIndex, to: index)
125+
return text.distance(from: text.startIndex, to: index)
126126
}
127127
return nil
128128
}()
@@ -137,7 +137,7 @@ public class Fuse {
137137
// What about in the other direction? (speed up)
138138
bestLocation = {
139139
if let index = text.lastIndexOf(pattern.text, position: location + pattern.len) {
140-
return text.characters.distance(from: text.startIndex, to: index)
140+
return text.distance(from: text.startIndex, to: index)
141141
}
142142
return nil
143143
}()

Fuse/Classes/FuseUtilities.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FuseUtilities {
1919
/// - Parameter scoreTextLength: Coerced version of text's length.
2020
/// - Returns: Overall score for match (0.0 = good, 1.0 = bad).
2121
static func calculateScore(_ pattern: String, e: Int, x: Int, loc: Int, distance: Int) -> Double {
22-
let len = pattern.characters.count
22+
let len = pattern.count
2323
let accuracy = Double(e) / Double(len)
2424
let proximity = abs(x - loc)
2525
if (distance == 0) {
@@ -33,13 +33,13 @@ class FuseUtilities {
3333
/// - Parameter pattern: The text to encode.
3434
/// - Returns: Hash of character locations.
3535
static func calculatePatternAlphabet(_ pattern: String) -> [Character: Int] {
36-
let len = pattern.characters.count
36+
let len = pattern.count
3737
var mask = [Character: Int]()
38-
for char in pattern.characters {
38+
for char in pattern {
3939
mask[char] = 0
4040
}
4141
for i in 0...len-1 {
42-
let c = pattern[pattern.characters.index(pattern.startIndex, offsetBy: i)]
42+
let c = pattern[pattern.index(pattern.startIndex, offsetBy: i)]
4343
mask[c] = mask[c]! | (1 << (len - i - 1))
4444
}
4545
return mask

Fuse/Classes/String+Fuse.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ extension String {
1414
/// - Parameter index: some index
1515
/// - Returns: the character at the provided index
1616
func char(at index: Int) -> Character? {
17-
if index >= self.characters.count {
17+
if index >= self.count {
1818
return nil
1919
}
20-
return self[self.characters.index(self.startIndex, offsetBy: index)]
20+
return self[self.index(self.startIndex, offsetBy: index)]
2121
}
2222

2323
/// Searches and returns the index within the string of the first occurrence of `searchStr`.
@@ -27,8 +27,8 @@ extension String {
2727
///
2828
/// - Returns: The index within the calling String object of the first occurrence of `searchStr`, starting the search at `position`. Returns `nil` if the value is not found.
2929
func index(of aString: String, startingFrom position: Int? = 0) -> String.Index? {
30-
let start: String.Index = self.characters.index(self.startIndex, offsetBy: position!)
31-
let range: Range<Index> = Range<Index>(start..<self.endIndex)
30+
let start: String.Index = self.index(self.startIndex, offsetBy: position!)
31+
let range: Range<Index> = Range<Index>.init(uncheckedBounds: (lower: start, upper: self.endIndex))
3232
return self.range(of: aString, options: .literal, range: range, locale: nil)?.lowerBound
3333
}
3434

@@ -39,10 +39,10 @@ extension String {
3939
///
4040
/// - Returns: The index of last occurrence of `searchStr`, searching backwards from `position`. Returns `nil` if the value is not found.
4141
func lastIndexOf(_ searchStr: String, position: Int? = 0) -> String.Index? {
42-
let len = self.characters.count
42+
let len = self.count
4343
let start = min(max(position!, 0), len)
44-
let searchLen = searchStr.characters.count
45-
let r: Range<Index> = Range<Index>(self.startIndex..<self.characters.index(self.startIndex, offsetBy: min(start + searchLen, len)))
44+
let searchLen = searchStr.count
45+
let r: Range<Index> = Range<Index>.init(uncheckedBounds: (lower: self.startIndex, upper: self.index(self.startIndex, offsetBy: min(start + searchLen, len))))
4646
if let range = self.range(of: searchStr, options: [.backwards, .literal], range: r) {
4747
return range.lowerBound
4848
} else {

0 commit comments

Comments
 (0)