File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Tests/SwiftSubtitlesTests Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -251,6 +251,36 @@ public extension Subtitles {
251251 }
252252}
253253
254+ // MARK: - Mapping
255+
256+ public extension Subtitles {
257+
258+ /// Create a new subtitles object by removing all cues with empty text
259+ func removingEmptyCues( ) -> Subtitles {
260+ Subtitles ( self . cues. filter { $0. text. count > 0 } )
261+ }
262+
263+ /// Returns a new subtitles object with positions matching the order of the cues
264+ /// - Returns: Subtitles
265+ func setIncrementingPositionValues( ) -> Subtitles {
266+ let cues = self . cues
267+ . enumerated ( )
268+ . map {
269+ let position = $0. 0 + 1
270+ let cue = $0. 1
271+ return Subtitles . Cue (
272+ identifier: cue. identifier,
273+ position: position,
274+ startTime: cue. startTime,
275+ duration: cue. duration,
276+ text: cue. text,
277+ speaker: cue. speaker
278+ )
279+ }
280+ return Subtitles ( cues)
281+ }
282+ }
283+
254284// MARK: - Validation and sanitization
255285
256286public extension Subtitles {
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ final class TimeShiftingTests: XCTestCase {
1616 let fileURL = Bundle . module. url ( forResource: " upc-video-subtitles-en " , withExtension: " vtt " ) !
1717 let subtitles = try Subtitles ( fileURL: fileURL, encoding: . utf8)
1818
19+ XCTAssertEqual ( 8 , subtitles. cues. count)
20+
1921 do {
2022 // Insert at the start
2123 let n = subtitles. timeShifting ( by: 1 )
You can’t perform that action at this time.
0 commit comments