Skip to content

Commit 45044b3

Browse files
committed
Fix backwards count of Indic graphemes
fix other bug add extra test
1 parent f698c3f commit 45044b3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

stdlib/public/core/StringGraphemeBreaking.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ extension _StringGuts {
390390
// If we're currently in an indic sequence (or if our lhs is a linking
391391
// consonant), then this check and everything underneath ensures that
392392
// we continue being in one and may check if this extend is a Virama.
393-
if state.isInIndicSequence || scalar1._isLinkingConsonant {
393+
if state.isInIndicSequence ||
394+
(!isBackwards && scalar1._isLinkingConsonant) {
394395
if y == .extend {
395396
let extendNormData = Unicode._NormData(scalar2, fastUpperbound: 0x300)
396397

@@ -440,7 +441,8 @@ extension _StringGuts {
440441
// GB999
441442
default:
442443
// GB9c
443-
if state.isInIndicSequence, state.hasSeenVirama, scalar2._isLinkingConsonant {
444+
if !isBackwards, state.isInIndicSequence, state.hasSeenVirama,
445+
scalar2._isLinkingConsonant {
444446
state.hasSeenVirama = false
445447
return false
446448
}

validation-test/stdlib/String.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,17 @@ StringTests.test("GraphemeBreaking.Indic Sequences") {
23322332
let test10 = "\u{003F}\u{094D}\u{0924}" // 2
23332333
expectEqual(2, test10.count)
23342334
expectBidirectionalCount(2, test10)
2335+
2336+
#if _runtime(_ObjC)
2337+
let test11Foreign = NSString(string: "\u{930}\u{93e}\u{91c}\u{94d}") // 2
2338+
let test11 = test11Foreign as String
2339+
expectEqual(2, test11.count)
2340+
expectBidirectionalCount(2, test11)
2341+
#endif
2342+
2343+
let test12 = "a\u{0915}\u{093C}\u{200D}\u{094D}\u{0924}a" // 3
2344+
expectEqual(3, test12.count)
2345+
expectBidirectionalCount(3, test12)
23352346
}
23362347

23372348
runAllTests()

0 commit comments

Comments
 (0)