-
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.
Signed-off-by: Ethan Dye <mrtops03@gmail.com>
- Loading branch information
Showing
4 changed files
with
96 additions
and
38 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Sources/macSubtitleOCR/Extensions/CollectionExtensions.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,18 @@ | ||
// | ||
// CollectionExtensions.swift | ||
// macSubtitleOCR | ||
// | ||
// Created by Ethan Dye on 9/24/24. | ||
// Copyright © 2024 Ethan Dye. All rights reserved. | ||
// | ||
|
||
extension Collection { | ||
func unfoldSubSequences(limitedTo maxLength: Int) -> UnfoldSequence<SubSequence, Index> { | ||
sequence(state: startIndex) { start in | ||
guard start < self.endIndex else { return nil } | ||
let end = self.index(start, offsetBy: maxLength, limitedBy: self.endIndex) ?? self.endIndex | ||
defer { start = end } | ||
return self[start ..< end] | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Sources/macSubtitleOCR/Extensions/StringProtocolExtensions.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,15 @@ | ||
// | ||
// StringProtocolExtensions.swift | ||
// macSubtitleOCR | ||
// | ||
// Created by Ethan Dye on 9/24/24. | ||
// Copyright © 2024 Ethan Dye. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension StringProtocol { | ||
var byte: UInt8? { UInt8(self, radix: 16) } | ||
var hexToBytes: [UInt8] { unfoldSubSequences(limitedTo: 2).compactMap(\.byte) } | ||
var hexToData: Data { .init(hexToBytes) } | ||
} |
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