Skip to content

Commit 8038a9b

Browse files
authored
Fixes word boundaries when string starts with punctuation (toptensoftware#98)
1 parent 2e8a37a commit 8038a9b

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Topten.RichTextKit.Test/WordBoundaryTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,32 @@ public void Punctuation2()
9191
Assert.Equal(9, boundaries[2]);
9292
}
9393

94+
[Fact]
95+
public void Punctuation3()
96+
{
97+
var str = ".Hello World";
98+
var boundaries = WordBoundaryAlgorithm.FindWordBoundaries(new Utf32Buffer(str).AsSlice()).ToList();
99+
100+
Assert.Equal(3, boundaries.Count);
101+
Assert.Equal(0, boundaries[0]);
102+
Assert.Equal(1, boundaries[1]);
103+
Assert.Equal(7, boundaries[2]);
104+
}
105+
106+
[Fact]
107+
public void Punctuation4()
108+
{
109+
var str = ".Hello.World.";
110+
var boundaries = WordBoundaryAlgorithm.FindWordBoundaries(new Utf32Buffer(str).AsSlice()).ToList();
111+
112+
Assert.Equal(5, boundaries.Count);
113+
Assert.Equal(0, boundaries[0]);
114+
Assert.Equal(1, boundaries[1]);
115+
Assert.Equal(6, boundaries[2]);
116+
Assert.Equal(7, boundaries[3]);
117+
Assert.Equal(12, boundaries[4]);
118+
}
119+
94120
[Fact]
95121
public void TestIsWordBoundary()
96122
{

Topten.RichTextKit/LineBreakAlgorithm/WordBoundaryAlgorithm.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public static IEnumerable<int> FindWordBoundaries(Slice<int> codePoints)
7777
// Switch to a different word kind without a space
7878
// just emit a word boundary here
7979
yield return i;
80+
// Update wordGroup to the new boundary class
81+
wordGroup = bg;
8082
}
8183
}
8284
}

0 commit comments

Comments
 (0)