-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from cocoatype/173-use-new-matching-for-detec…
…tions Use new matching for detections
- Loading branch information
Showing
6 changed files
with
78 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Modules/Capabilities/Observations/Sources/Observations/CombinedCharacterObservation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Created by Geoff Pado on 6/25/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import Foundation | ||
|
||
public struct CombinedCharacterObservation { | ||
public let textObservationUUID: UUID | ||
private let characterObservations: [CharacterObservation] | ||
public let associatedString: String | ||
|
||
public init?(characterObservations: [CharacterObservation]) { | ||
guard let firstUUID = characterObservations.first?.textObservationUUID, | ||
characterObservations.allSatisfy({ $0.textObservationUUID == firstUUID }), | ||
let firstString = characterObservations.first?.associatedString | ||
else { return nil } | ||
|
||
self.textObservationUUID = firstUUID | ||
self.characterObservations = characterObservations | ||
self.associatedString = firstString | ||
} | ||
|
||
public func characterObservations(with substrings: [Substring]) -> [CharacterObservation] { | ||
characterObservations.filter { observation in | ||
guard let observationRange = observation.range else { return false } | ||
return substrings.contains { substring in | ||
let substringRange = substring.startIndex ..< substring.endIndex | ||
return observationRange.overlaps(substringRange) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters