@@ -245,6 +245,16 @@ extension BidirectionalCollection where SubSequence == Substring {
245
245
/// - Returns: `true` if the regex was found in the collection, otherwise
246
246
/// `false`.
247
247
public func contains (_ regex : some RegexComponent) -> Bool
248
+
249
+ /// Returns a Boolean value indicating whether the collection contains the
250
+ /// given regex.
251
+ /// - Parameter content: A closure to produce a `RegexComponent` to search for
252
+ /// within this collection.
253
+ /// - Returns: `true` if the regex was found in the collection, otherwise
254
+ /// `false`.
255
+ public func contains (
256
+ @RegexComponentBuilder _ content : () -> some RegexComponent
257
+ ) -> Bool
248
258
}
249
259
```
250
260
@@ -258,6 +268,15 @@ extension BidirectionalCollection where SubSequence == Substring {
258
268
/// - Returns: `true` if the initial elements of the sequence matches the
259
269
/// beginning of `regex`; otherwise, `false`.
260
270
public func starts (with regex : some RegexComponent) -> Bool
271
+
272
+ /// Returns a Boolean value indicating whether the initial elements of the
273
+ /// sequence are the same as the elements in the specified regex.
274
+ /// - Parameter content: A closure to produce a `RegexComponent` to compare.
275
+ /// - Returns: `true` if the initial elements of the sequence matches the
276
+ /// beginning of `regex`; otherwise, `false`.
277
+ public func starts (
278
+ @RegexComponentBuilder with content : () -> some RegexComponent
279
+ ) -> Bool
261
280
}
262
281
```
263
282
@@ -324,6 +343,15 @@ extension BidirectionalCollection where SubSequence == Substring {
324
343
/// - Returns: A new subsequence containing the elements of the collection
325
344
/// that does not match `prefix` from the start.
326
345
public func trimmingPrefix (_ regex : some RegexComponent) -> SubSequence
346
+
347
+ /// Returns a new collection of the same type by removing `prefix` from the
348
+ /// start.
349
+ /// - Parameter _content A closure to produce a `RegexComponent` to be removed.
350
+ /// - Returns: A collection containing the elements that does not match
351
+ /// `prefix` from the start.
352
+ public func trimmingPrefix (
353
+ @RegexComponentBuilder _ content : () -> some RegexComponent
354
+ ) -> SubSequence
327
355
}
328
356
329
357
extension RangeReplaceableCollection
@@ -332,6 +360,12 @@ extension RangeReplaceableCollection
332
360
/// Removes the initial elements that matches the given regex.
333
361
/// - Parameter regex: The regex to remove from this collection.
334
362
public mutating func trimPrefix (_ regex : some RegexComponent)
363
+
364
+ /// Removes the initial elements that matches the given regex.
365
+ /// - Parameter content: A closure to produce a `RegexComponent` to be removed.
366
+ public mutating func trimPrefix (
367
+ @RegexComponentBuilder _ content : () -> some RegexComponent
368
+ )
335
369
}
336
370
```
337
371
@@ -365,6 +399,16 @@ extension BidirectionalCollection where SubSequence == Substring {
365
399
/// - Returns: A range in the collection of the first occurrence of `regex`.
366
400
/// Returns `nil` if `regex` is not found.
367
401
public func firstRange (of regex : some RegexComponent) -> Range <Index >?
402
+
403
+ /// Finds and returns the range of the first occurrence of a given regex
404
+ /// within the collection.
405
+ /// - Parameter content: A closure to produce a `RegexComponent` to search for
406
+ /// within this collection.
407
+ /// - Returns: A range in the collection of the first occurrence of regex.
408
+ /// Returns `nil` if not found.
409
+ public func firstRange (
410
+ @RegexComponentBuilder of content : () -> some RegexComponent
411
+ ) -> Range <Index >?
368
412
}
369
413
```
370
414
@@ -388,6 +432,16 @@ extension BidirectionalCollection where SubSequence == Substring {
388
432
/// - Returns: A collection or ranges in the receiver of all occurrences of
389
433
/// `regex`. Returns an empty collection if `regex` is not found.
390
434
public func ranges (of regex : some RegexComponent) -> some Collection <Range <Index >>
435
+
436
+ /// Finds and returns the ranges of the all occurrences of a given sequence
437
+ /// within the collection.
438
+ /// - Parameter content: A closure to produce a `RegexComponent` to search for
439
+ /// within this collection.
440
+ /// - Returns: A collection or ranges in the receiver of all occurrences of
441
+ /// regex. Returns an empty collection if not found.
442
+ public func ranges (
443
+ @RegexComponentBuilder of content : () -> some RegexComponent
444
+ ) -> some Collection <Range <Index >>
391
445
}
392
446
```
393
447
@@ -401,15 +455,37 @@ extension BidirectionalCollection where SubSequence == Substring {
401
455
/// there isn't a match.
402
456
public func firstMatch <R : RegexComponent >(of regex : R) -> Regex<R.RegexOutput>.Match?
403
457
458
+ /// Returns the first match of the specified regex within the collection.
459
+ /// - Parameter content: A closure to produce a `RegexComponent` to search for.
460
+ /// - Returns: The first match of regex in the collection, or `nil` if
461
+ /// there isn't a match.
462
+ public func firstMatch <R : RegexComponent >(
463
+ @RegexComponentBuilder of content : () -> R
464
+ ) -> Regex<R.RegexOutput>.Match?
465
+
404
466
/// Match a regex in its entirety.
405
467
/// - Parameter regex: The regex to match against.
406
468
/// - Returns: The match if there is one, or `nil` if none.
407
469
public func wholeMatch <R : RegexComponent >(of regex : R) -> Regex<R.RegexOutput>.Match?
408
470
471
+ /// Match a regex in its entirety.
472
+ /// - Parameter content: A closure to produce a `RegexComponent` to match against.
473
+ /// - Returns: The match if there is one, or `nil` if none.
474
+ public func wholeMatch <R : RegexComponent >(
475
+ @RegexComponentBuilder of content : () -> R
476
+ ) -> Regex<R.RegexOutput>.Match?
477
+
409
478
/// Match part of the regex, starting at the beginning.
410
479
/// - Parameter regex: The regex to match against.
411
480
/// - Returns: The match if there is one, or `nil` if none.
412
481
public func prefixMatch <R : RegexComponent >(of regex : R) -> Regex<R.RegexOutput>.Match?
482
+
483
+ /// Match part of the regex, starting at the beginning.
484
+ /// - Parameter content: A closure to produce a `RegexComponent` to match against.
485
+ /// - Returns: The match if there is one, or `nil` if none.
486
+ public func prefixMatch <R : RegexComponent >(
487
+ @RegexComponentBuilder of content : () -> R
488
+ ) -> Regex<R.RegexOutput>.Match?
413
489
}
414
490
```
415
491
@@ -421,6 +497,13 @@ extension BidirectionalCollection where SubSequence == Substring {
421
497
/// - Parameter regex: The regex to search for.
422
498
/// - Returns: A collection of matches of `regex`.
423
499
public func matches <R : RegexComponent >(of regex : R) -> some Collection <Regex<R.RegexOuput>.Match>
500
+
501
+ /// Returns a collection containing all matches of the specified regex.
502
+ /// - Parameter content: A closure to produce a `RegexComponent` to search for.
503
+ /// - Returns: A collection of matches of `regex`.
504
+ public func matches <R : RegexComponent >(
505
+ @RegexComponentBuilder of content : () -> R
506
+ ) -> some Collection <Regex<R.RegexOutput>.Match>
424
507
}
425
508
```
426
509
@@ -490,6 +573,23 @@ extension RangeReplaceableCollection where SubSequence == Substring {
490
573
subrange : Range <Index >,
491
574
maxReplacements : Int = .max
492
575
) -> Self where Replacement.Element == Element
576
+
577
+ /// Returns a new collection in which all occurrences of a sequence matching
578
+ /// the given regex are replaced by another collection.
579
+ /// - Parameters:
580
+ /// - replacement: The new elements to add to the collection.
581
+ /// - subrange: The range in the collection in which to search for `regex`.
582
+ /// - maxReplacements: A number specifying how many occurrences of the
583
+ /// sequence matching `regex` to replace. Default is `Int.max`.
584
+ /// - content: A closure to produce a `RegexComponent` to replace.
585
+ /// - Returns: A new collection in which all occurrences of subsequence
586
+ /// matching `regex` in `subrange` are replaced by `replacement`.
587
+ public func replacing <Replacement : Collection >(
588
+ with replacement : Replacement,
589
+ subrange : Range <Index >,
590
+ maxReplacements : Int = .max ,
591
+ @RegexComponentBuilder content : () -> some RegexComponent
592
+ ) -> Self where Replacement.Element == Element
493
593
494
594
/// Returns a new collection in which all occurrences of a sequence matching
495
595
/// the given regex are replaced by another collection.
@@ -506,6 +606,21 @@ extension RangeReplaceableCollection where SubSequence == Substring {
506
606
maxReplacements : Int = .max
507
607
) -> Self where Replacement.Element == Element
508
608
609
+ /// Returns a new collection in which all occurrences of a sequence matching
610
+ /// the given regex are replaced by another collection.
611
+ /// - Parameters:
612
+ /// - replacement: The new elements to add to the collection.
613
+ /// - maxReplacements: A number specifying how many occurrences of the
614
+ /// sequence matching `regex` to replace. Default is `Int.max`.
615
+ /// - content: A closure to produce a `RegexComponent` to replace.
616
+ /// - Returns: A new collection in which all occurrences of subsequence
617
+ /// matching `regex` are replaced by `replacement`.
618
+ public func replacing <Replacement : Collection >(
619
+ with replacement : Replacement,
620
+ maxReplacements : Int = .max ,
621
+ @RegexComponentBuilder content : () -> some RegexComponent
622
+ ) -> Self where Replacement.Element == Element
623
+
509
624
/// Replaces all occurrences of the sequence matching the given regex with
510
625
/// a given collection.
511
626
/// - Parameters:
@@ -518,6 +633,19 @@ extension RangeReplaceableCollection where SubSequence == Substring {
518
633
with replacement : Replacement,
519
634
maxReplacements : Int = .max
520
635
) where Replacement.Element == Element
636
+
637
+ /// Replaces all occurrences of the sequence matching the given regex with
638
+ /// a given collection.
639
+ /// - Parameters:
640
+ /// - replacement: The new elements to add to the collection.
641
+ /// - maxReplacements: A number specifying how many occurrences of the
642
+ /// sequence matching `regex` to replace. Default is `Int.max`.
643
+ /// - content: A closure to produce a `RegexComponent` to replace.
644
+ public mutating func replace <Replacement : Collection >(
645
+ with replacement : Replacement,
646
+ maxReplacements : Int = .max ,
647
+ @RegexComponentBuilder content : () -> some RegexComponent
648
+ ) -> Self where Replacement.Element == Element
521
649
522
650
/// Returns a new collection in which all occurrences of a sequence matching
523
651
/// the given regex are replaced by another regex match.
@@ -536,6 +664,24 @@ extension RangeReplaceableCollection where SubSequence == Substring {
536
664
maxReplacements : Int = .max ,
537
665
with replacement : (Regex<R.RegexOutput>.Match) throws -> Replacement
538
666
) rethrows -> Self where Replacement.Element == Element
667
+
668
+ /// Returns a new collection in which all occurrences of a sequence matching
669
+ /// the given regex are replaced by another regex match.
670
+ /// - Parameters:
671
+ /// - subrange: The range in the collection in which to search for `regex`.
672
+ /// - maxReplacements: A number specifying how many occurrences of the
673
+ /// sequence matching `regex` to replace. Default is `Int.max`.
674
+ /// - content: A closure to produce a `RegexComponent` to replace.
675
+ /// - replacement: A closure that receives the full match information,
676
+ /// including captures, and returns a replacement collection.
677
+ /// - Returns: A new collection in which all occurrences of subsequence
678
+ /// matching `regex` are replaced by `replacement`.
679
+ public func replacing <R : RegexComponent , Replacement : Collection >(
680
+ subrange : Range <Index >,
681
+ maxReplacements : Int = .max ,
682
+ @RegexComponentBuilder content : () -> R,
683
+ with replacement : (Regex<R.RegexOutput>.Match) throws -> Replacement
684
+ ) rethrows -> Self where Replacement.Element == Element
539
685
540
686
/// Returns a new collection in which all occurrences of a sequence matching
541
687
/// the given regex are replaced by another collection.
@@ -552,6 +698,22 @@ extension RangeReplaceableCollection where SubSequence == Substring {
552
698
maxReplacements : Int = .max ,
553
699
with replacement : (Regex<R.RegexOuput>.Match) throws -> Replacement
554
700
) rethrows -> Self where Replacement.Element == Element
701
+
702
+ /// Returns a new collection in which all occurrences of a sequence matching
703
+ /// the given regex are replaced by another collection.
704
+ /// - Parameters:
705
+ /// - maxReplacements: A number specifying how many occurrences of the
706
+ /// sequence matching `regex` to replace. Default is `Int.max`.
707
+ /// - content: A closure to produce a `RegexComponent` to replace.
708
+ /// - replacement: A closure that receives the full match information,
709
+ /// including captures, and returns a replacement collection.
710
+ /// - Returns: A new collection in which all occurrences of subsequence
711
+ /// matching `regex` are replaced by `replacement`.
712
+ public func replacing <R : RegexComponent , Replacement : Collection >(
713
+ maxReplacements : Int = .max ,
714
+ @RegexComponentBuilder content : () -> R,
715
+ with replacement : (Regex<R.RegexOutput>.Match) throws -> Replacement
716
+ ) rethrows -> Self where Replacement.Element == Element
555
717
556
718
/// Replaces all occurrences of the sequence matching the given regex with
557
719
/// a given collection.
@@ -566,6 +728,20 @@ extension RangeReplaceableCollection where SubSequence == Substring {
566
728
maxReplacements : Int = .max ,
567
729
with replacement : (Regex<R.RegexOutput>.Match) throws -> Replacement
568
730
) rethrows where Replacement.Element == Element
731
+
732
+ /// Replaces all occurrences of the sequence matching the given regex with
733
+ /// a given collection.
734
+ /// - Parameters:
735
+ /// - maxReplacements: A number specifying how many occurrences of the
736
+ /// sequence matching `regex` to replace. Default is `Int.max`.
737
+ /// - content: A closure to produce a `RegexComponent` to replace.
738
+ /// - replacement: A closure that receives the full match information,
739
+ /// including captures, and returns a replacement collection.
740
+ public mutating func replace <R : RegexComponent , Replacement : Collection >(
741
+ maxReplacements : Int = .max ,
742
+ @RegexComponentBuilder content : () -> R,
743
+ with replacement : (Regex<R.RegexOutput>.Match) throws -> Replacement
744
+ ) rethrows where Replacement.Element == Element
569
745
}
570
746
```
571
747
@@ -613,6 +789,25 @@ extension BidirectionalCollection where SubSequence == Substring {
613
789
maxSplits : Int = Int .max ,
614
790
omittingEmptySubsequences : Bool = true
615
791
) -> some Collection <Substring>
792
+
793
+ /// Returns the longest possible subsequences of the collection, in order,
794
+ /// around subsequence that match the given separator regex.
795
+ ///
796
+ /// - Parameters:
797
+ /// - maxSplits: The maximum number of times to split the collection,
798
+ /// or one less than the number of subsequences to return.
799
+ /// - omittingEmptySubsequences: If `false`, an empty subsequence is
800
+ /// returned in the result for each consecutive pair of matches
801
+ /// and for each match at the start or end of the collection. If
802
+ /// `true`, only nonempty subsequences are returned.
803
+ /// - separator: A closure to produce a `RegexComponent` to be split upon.
804
+ /// - Returns: A collection of substrings, split from this collection's
805
+ /// elements.
806
+ public func split (
807
+ maxSplits : Int = Int .max ,
808
+ omittingEmptySubsequences : Bool = true ,
809
+ @RegexComponentBuilder separator : () -> some RegexComponent
810
+ ) -> some Collection <Substring>
616
811
}
617
812
```
618
813
0 commit comments