-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d631600
commit 55198bb
Showing
8 changed files
with
106 additions
and
67 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// String+Split.swift | ||
// SnapshotPreviews | ||
// | ||
// Created by Noah Martin on 1/17/25. | ||
// | ||
|
||
extension String { | ||
var splittingHumanReadableName: [String] { | ||
return split(separator: ".").flatMap { $0.split(separator: "_") } | ||
.joined(separator: " ") | ||
.splitBefore(separator: { $0.isUpperCase && !($1?.isUpperCase ?? true) }) | ||
.map { String($0).trimmingCharacters(in: .whitespaces) } | ||
.filter { $0.count > 0 } | ||
} | ||
} | ||
|
||
extension Sequence { | ||
func splitBefore( | ||
separator isSeparator: (Iterator.Element, Iterator.Element?) throws -> Bool | ||
) rethrows -> [AnySequence<Iterator.Element>] { | ||
var result: [AnySequence<Iterator.Element>] = [] | ||
var subSequence: [Iterator.Element] = [] | ||
|
||
var iterator = self.makeIterator() | ||
var currentElement = iterator.next() | ||
while let element = currentElement { | ||
let nextElement = iterator.next() | ||
if try isSeparator(element, nextElement) { | ||
if !subSequence.isEmpty { | ||
result.append(AnySequence(subSequence)) | ||
} | ||
subSequence = [element] | ||
} | ||
else { | ||
subSequence.append(element) | ||
} | ||
currentElement = nextElement | ||
} | ||
result.append(AnySequence(subSequence)) | ||
return result | ||
} | ||
} | ||
|
||
extension Character { | ||
var isUpperCase: Bool { return String(self) == String(self).uppercased() } | ||
} |