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

#22 Updated for swift 5 #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Fuse/Classes/Fuse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class Fuse {
/// - pattern: The pattern to search for. This is created by calling `createPattern`
/// - aString: The string in which to search for the pattern
/// - Returns: A tuple containing a `score` between `0.0` (exact match) and `1` (not a match), and `ranges` of the matched characters.
public func search(_ pattern: Pattern?, in aString: String) -> (score: Double, ranges: [CountableClosedRange<Int>])? {
public func search(_ pattern: Pattern?, in aString: String) -> (score: Double, ranges: [ClosedRange<Int>])? {
guard let pattern = pattern else {
return nil
}
Expand All @@ -113,7 +113,7 @@ public class Fuse {

// Exact match
if (pattern.text == text) {
return (0, [CountableClosedRange<Int>(0...textLength - 1)])
return (0, [0...textLength - 1])
}

let location = self.location
Expand Down
8 changes: 4 additions & 4 deletions Fuse/Classes/FuseUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ class FuseUtilities {
/// - Parameter mask: A string representing the value to search for.
///
/// - Returns: `CountableClosedRange<Int>` array.
static func findRanges(_ mask: [Int]) -> [CountableClosedRange<Int>] {
var ranges = [CountableClosedRange<Int>]()
static func findRanges(_ mask: [Int]) -> [ClosedRange<Int>] {
var ranges = [ClosedRange<Int>]()
var start: Int = -1
var end: Int = -1
for (n, bit) in mask.enumerated() {
if bit == 1 && start == -1 {
start = n
} else if bit == 0 && start != -1 {
end = n - 1
ranges.append(CountableClosedRange<Int>(start...end))
ranges.append(start...end)
start = -1
}
}
if mask.last == 1 {
ranges.append(CountableClosedRange<Int>(start...mask.count - 1))
ranges.append(start...(mask.count - 1))
}
return ranges
}
Expand Down
2 changes: 1 addition & 1 deletion Fuse/Classes/String+Fuse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension String {
return nil
}

if self.startIndex.encodedOffset + position > self.endIndex.encodedOffset {
if self.startIndex.utf16Offset(in: self) + position > self.endIndex.utf16Offset(in: self) {
return nil
}

Expand Down