@@ -407,7 +407,7 @@ extension Unicode.Scalar {
407
407
}
408
408
}
409
409
410
- internal struct _GraphemeBreakingState {
410
+ internal struct _GraphemeBreakingState : Sendable , Equatable {
411
411
// When we're looking through an indic sequence, one of the requirements is
412
412
// that there is at LEAST 1 Virama present between two linking consonants.
413
413
// This value helps ensure that when we ultimately need to decide whether or
@@ -436,6 +436,18 @@ internal struct _GraphemeBreakingState {
436
436
var shouldBreakRI = false
437
437
}
438
438
439
+ extension _GraphemeBreakingState : CustomStringConvertible {
440
+ var description : String {
441
+ var r = " [ "
442
+ if hasSeenVirama { r += " V " }
443
+ if isInEmojiSequence { r += " E " }
444
+ if isInIndicSequence { r += " I " }
445
+ if shouldBreakRI { r += " R " }
446
+ r += " ] "
447
+ return r
448
+ }
449
+ }
450
+
439
451
extension Unicode {
440
452
/// A state machine for recognizing character (i.e., extended grapheme
441
453
/// cluster) boundaries in an arbitrary series of Unicode scalars.
@@ -448,7 +460,7 @@ extension Unicode {
448
460
/// `String` splits its contents into `Character` values.
449
461
@available ( SwiftStdlib 5 . 8 , * )
450
462
public // SPI(Foundation) FIXME: We need API for this
451
- struct _CharacterRecognizer {
463
+ struct _CharacterRecognizer : Sendable {
452
464
internal var _previous : Unicode . Scalar
453
465
internal var _state : _GraphemeBreakingState
454
466
@@ -547,6 +559,21 @@ extension Unicode {
547
559
}
548
560
}
549
561
562
+ @available ( SwiftStdlib 5 . 8 , * )
563
+ extension Unicode . _CharacterRecognizer : Equatable {
564
+ public static func == ( left: Self , right: Self ) -> Bool {
565
+ left. _previous == right. _previous && left. _state == right. _state
566
+ }
567
+ }
568
+
569
+ @available ( SwiftStdlib 5 . 8 , * )
570
+ extension Unicode . _CharacterRecognizer : CustomStringConvertible {
571
+ public var description : String {
572
+ return " \( _state) U+ \( String ( _previous. value, radix: 16 , uppercase: true ) ) "
573
+ }
574
+ }
575
+
576
+
550
577
extension _StringGuts {
551
578
// Returns the stride of the grapheme cluster starting at offset `index`,
552
579
// assuming it is on a grapheme cluster boundary.
0 commit comments