Fixes #2655. Should be avoid cast to char on a Rune ctor which always fallback for a UTF16 char. (#2656)

This commit is contained in:
BDisp
2023-05-22 07:14:12 +01:00
committed by GitHub
parent ef6f355f50
commit 59a7ff95b3
2 changed files with 11 additions and 2 deletions

View File

@@ -332,7 +332,7 @@ class CharMap : ScrollView {
}
private void CopyCodePoint () => Clipboard.Contents = $"U+{SelectedCodePoint:x5}";
private void CopyGlyph () => Clipboard.Contents = $"{new Rune ((char)SelectedCodePoint)}";
private void CopyGlyph () => Clipboard.Contents = $"{new Rune (SelectedCodePoint)}";
public override void OnDrawContent (Rect contentArea)
{
@@ -553,7 +553,7 @@ class CharMap : ScrollView {
//}
}
var title = $"{ToCamelCase (name)} - {new Rune ((char)SelectedCodePoint)} U+{SelectedCodePoint:x4}";
var title = $"{ToCamelCase (name)} - {new Rune (SelectedCodePoint)} U+{SelectedCodePoint:x4}";
switch (MessageBox.Query (title, decResponse, "Copy _Glyph", "Copy Code _Point", "Cancel")) {
case 0:
CopyGlyph ();

View File

@@ -711,4 +711,13 @@ public class RuneTests {
Assert.Equal (utf16Length, r.Utf16SequenceLength);
Assert.Equal (utf8Length, r.Utf8SequenceLength);
}
[Fact]
public void Cast_To_Char_Durrogate_Pair_Return_UTF16 ()
{
Assert.NotEqual ("𝔹", $"{new Rune (unchecked((char)0x1d539))}");
Assert.Equal ("픹", $"{new Rune (unchecked((char)0x1d539))}");
Assert.Equal ("픹", $"{new Rune (0xd539)}");
Assert.Equal ("𝔹", $"{new Rune (0x1d539)}");
}
}