Skip to content

Commit 06ea4da

Browse files
committed
Use text element indices not string indices for PreviousCharacter
1 parent 4355c5f commit 06ea4da

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/SIL.Machine/PunctuationAnalysis/QuotationMarkStringMatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public string PreviousCharacter
7575
if (previousSegment != null && !TextSegment.MarkerIsInPrecedingContext(UsfmMarkerType.Paragraph))
7676
{
7777
return new StringInfo(previousSegment.Text).SubstringByTextElements(
78-
previousSegment.Text.Length - 1,
78+
StringInfo.ParseCombiningCharacters(previousSegment.Text).Length - 1,
7979
1
8080
);
8181
}

tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkStringMatchTests.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,24 @@ public void GetPreviousCharacter()
188188
0,
189189
1
190190
);
191-
;
191+
Assert.IsNull(quotationMarkStringMatch.PreviousCharacter);
192+
192193
quotationMarkStringMatch = new QuotationMarkStringMatch(
193194
new TextSegment.Builder().SetText("\u201c\u201d").Build(),
194195
1,
195196
2
196197
);
197198
Assert.That(quotationMarkStringMatch.PreviousCharacter, Is.EqualTo("“"));
199+
200+
quotationMarkStringMatch = new QuotationMarkStringMatch(
201+
new TextSegment.Builder()
202+
.SetText("\"उत्पत्ति पुस्तकले")
203+
.SetPreviousSegment(new TextSegment.Builder().SetText("उत्पत्ति पुस्तकले").Build())
204+
.Build(),
205+
0,
206+
1
207+
);
208+
Assert.That(quotationMarkStringMatch.PreviousCharacter, Is.EqualTo("ले"));
198209
}
199210

200211
[Test]

0 commit comments

Comments
 (0)