2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -459,7 +459,7 @@ extension _StringGuts {
459
459
460
460
while true {
461
461
guard let ( scalar2, nextIndex) = nextScalar ( index) else { break }
462
- if shouldBreak ( between: scalar, and: scalar2, at : index , with : & state ) {
462
+ if state . shouldBreak ( between: scalar, and: scalar2) {
463
463
break
464
464
}
465
465
index = nextIndex
@@ -505,7 +505,7 @@ extension _StringGuts {
505
505
}
506
506
}
507
507
508
- extension _StringGuts {
508
+ extension _GraphemeBreakingState {
509
509
// Return true if there is an extended grapheme cluster boundary between two
510
510
// scalars, based on state information previously collected about preceding
511
511
// scalars.
@@ -517,11 +517,9 @@ extension _StringGuts {
517
517
//
518
518
// This is based on the Unicode Annex #29 for [Grapheme Cluster Boundary
519
519
// Rules](https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules).
520
- internal func shouldBreak(
520
+ internal mutating func shouldBreak(
521
521
between scalar1: Unicode . Scalar ,
522
- and scalar2: Unicode . Scalar ,
523
- at index: Int ,
524
- with state: inout _GraphemeBreakingState
522
+ and scalar2: Unicode . Scalar
525
523
) -> Bool {
526
524
// GB3
527
525
if scalar1. value == 0xD , scalar2. value == 0xA {
@@ -545,8 +543,8 @@ extension _StringGuts {
545
543
var enterIndicSequence = false
546
544
547
545
defer {
548
- state . isInEmojiSequence = enterEmojiSequence
549
- state . isInIndicSequence = enterIndicSequence
546
+ self . isInEmojiSequence = enterEmojiSequence
547
+ self . isInIndicSequence = enterIndicSequence
550
548
}
551
549
552
550
switch ( x, y) {
@@ -591,14 +589,14 @@ extension _StringGuts {
591
589
// continue the grapheme cluster by combining more scalars later. If we're
592
590
// not currently in an emoji sequence, but our lhs scalar is a pictograph,
593
591
// then that's a signal that it's the start of an emoji sequence.
594
- if state . isInEmojiSequence || x == . extendedPictographic {
592
+ if self . isInEmojiSequence || x == . extendedPictographic {
595
593
enterEmojiSequence = true
596
594
}
597
595
598
596
// If we're currently in an indic sequence (or if our lhs is a linking
599
597
// consonant), then this check and everything underneath ensures that
600
598
// we continue being in one and may check if this extend is a Virama.
601
- if state . isInIndicSequence || scalar1. _isLinkingConsonant {
599
+ if self . isInIndicSequence || scalar1. _isLinkingConsonant {
602
600
if y == . extend {
603
601
let extendNormData = Unicode . _NormData ( scalar2, fastUpperbound: 0x300 )
604
602
@@ -611,7 +609,7 @@ extension _StringGuts {
611
609
enterIndicSequence = true
612
610
613
611
if scalar2. _isVirama {
614
- state . hasSeenVirama = true
612
+ self . hasSeenVirama = true
615
613
}
616
614
}
617
615
@@ -627,32 +625,34 @@ extension _StringGuts {
627
625
628
626
// GB11
629
627
case ( . zwj, . extendedPictographic) :
630
- return !state . isInEmojiSequence
628
+ return !self . isInEmojiSequence
631
629
632
630
// GB12 & GB13
633
631
case ( . regionalIndicator, . regionalIndicator) :
634
632
defer {
635
- state . shouldBreakRI. toggle ( )
633
+ self . shouldBreakRI. toggle ( )
636
634
}
637
635
638
- return state . shouldBreakRI
636
+ return self . shouldBreakRI
639
637
640
638
// GB999
641
639
default :
642
640
// GB9c
643
641
if
644
- state . isInIndicSequence,
645
- state . hasSeenVirama,
642
+ self . isInIndicSequence,
643
+ self . hasSeenVirama,
646
644
scalar2. _isLinkingConsonant
647
645
{
648
- state . hasSeenVirama = false
646
+ self . hasSeenVirama = false
649
647
return false
650
648
}
651
649
652
650
return true
653
651
}
654
652
}
653
+ }
655
654
655
+ extension _StringGuts {
656
656
// Return true if there is an extended grapheme cluster boundary between two
657
657
// scalars, with no previous knowledge about preceding scalars.
658
658
//
0 commit comments