Skip to content

Commit 8de76c5

Browse files
committed
Use Unicode 17 Indic extend data
1 parent 711c076 commit 8de76c5

2 files changed

Lines changed: 21 additions & 27 deletions

File tree

src/RoyalTerminal.Unicode/Unicode/IndicConjunctBreakData.cs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for details.
33
// Unicode 17.0 Indic_Conjunct_Break data used by UAX #29 rule GB9c.
44

5-
using System.Globalization;
65
using System.Runtime.CompilerServices;
7-
using System.Text;
86

97
namespace RoyalTerminal.Unicode;
108

@@ -32,31 +30,13 @@ public static IndicConjunctBreakClass Get(Codepoint codepoint)
3230
return IndicConjunctBreakClass.Consonant;
3331
}
3432

35-
// Include the non-mark members and Unicode 17 additions that may not
36-
// yet have a mark category in the current .NET Unicode tables.
37-
if (value is 0x200D or
38-
>= 0x1ACF and <= 0x1ADD or
39-
>= 0x1AE0 and <= 0x1AEB or
40-
>= 0xFF9E and <= 0xFF9F or
41-
>= 0x10EFA and <= 0x10EFB or
42-
0x11B60 or
43-
>= 0x11B62 and <= 0x11B64 or
44-
0x11B66 or
45-
>= 0x1F3FB and <= 0x1F3FF or
46-
0x1E6E3 or
47-
0x1E6E6 or
48-
>= 0x1E6EE and <= 0x1E6EF or
49-
0x1E6F5 or
50-
>= 0xE0020 and <= 0xE007F)
51-
{
52-
return IndicConjunctBreakClass.Extend;
53-
}
54-
55-
UnicodeCategory category =
56-
Rune.GetUnicodeCategory(new Rune(checked((int)value)));
57-
return category is UnicodeCategory.NonSpacingMark
58-
or UnicodeCategory.SpacingCombiningMark
59-
or UnicodeCategory.EnclosingMark
33+
// Unicode 17's generated InCB=Extend set is the generated GCB Extend
34+
// and ZWJ sets, excluding InCB Linkers (handled above) and ZWNJ.
35+
// General Unicode mark categories are not equivalent: for example,
36+
// U+0903 is a spacing combining mark but has InCB=None.
37+
return value != 0x200C &&
38+
codepoint.GraphemeBreakClass is GraphemeBreakClass.Extend
39+
or GraphemeBreakClass.ZWJ
6040
? IndicConjunctBreakClass.Extend
6141
: IndicConjunctBreakClass.None;
6242
}

tests/RoyalTerminal.Tests/UnicodeWidthTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void ManagedGraphemeWidths_MatchPinnedGhosttyEdgeCases()
7272
[0x1F3F4, 0x200D, 0x2620, 0xFE0F],
7373
[0x1F1E6, 0x1F1E7, 0x1F1E8],
7474
[0x0915, 0x094D, 0x0937, (uint)'A'],
75+
[0x0915, 0x094D, 0x0903, 0x0937],
7576
[0x0600, (uint)'A'],
7677
[0x0301, 0x0302],
7778
[0xD800, 0x0301],
@@ -166,6 +167,19 @@ public void FirstGraphemeWidth_ConsumesUnicode17IndicConjunct()
166167
Assert.Equal(2, width);
167168
}
168169

170+
[Fact]
171+
public void FirstGraphemeWidth_StopsIndicConjunctAtIncbNoneSpacingMark()
172+
{
173+
uint[] codepoints = [0x0915, 0x094D, 0x0903, 0x0937];
174+
175+
int consumed = TerminalCellWidthCalculator.GetFirstGraphemeWidth(
176+
codepoints,
177+
out int width);
178+
179+
Assert.Equal(3, consumed);
180+
Assert.Equal(2, width);
181+
}
182+
169183
[Fact]
170184
public void FirstGraphemeWidth_MatchesPinnedGhosttyForPrependCluster()
171185
{

0 commit comments

Comments
 (0)